Skip to content

Commit

Permalink
dump
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Schmid <[email protected]>
  • Loading branch information
Joshua Schmid committed Aug 8, 2018
1 parent b6427e9 commit eb18e64
Showing 1 changed file with 80 additions and 76 deletions.
156 changes: 80 additions & 76 deletions tests/unit/_modules/test_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import pytest
import sys
import random
sys.path.insert(0, 'srv/salt/_modules')

sys.path.insert(0, "srv/salt/_modules")
from srv.salt._modules import proposal
from srv.salt._modules import helper
from tests.unit.helper.output import OutputHelper, GenHwinfo


class TestProposal(object):

@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def output_helper(self):
yield OutputHelper()

Expand All @@ -25,46 +25,43 @@ def replaced_disk_hdd_ratio_4(self):

@pytest.fixture()
def replaced_disk_ssd(self):
return self.replace_disk(type='ssd')
return self.replace_disk(type="ssd")

@pytest.fixture()
def replaced_disk_nvme(self):
return self.replace_disk(type='nvme')
return self.replace_disk(type="nvme")

def test_parse_filter(self, output_helper):
# test defaults
p = proposal.Proposal([])
self.check_proposal_init(p, 5, 5, 0, 0, 0, 0)

p = proposal.Proposal([], ratio=2, db_ratio=1,
data='50', journal='20')
p = proposal.Proposal([], ratio=2, db_ratio=1, data="50", journal="20")
self.check_proposal_init(p, 2, 1, 50, 0, 20, 0)

p = proposal.Proposal([], ratio=2, db_ratio=1,
data='20-50', journal='5-20')
p = proposal.Proposal([], ratio=2, db_ratio=1, data="20-50", journal="5-20")
self.check_proposal_init(p, 2, 1, 20, 50, 5, 20)

p = proposal.Proposal([], ratio=2, db_ratio=2,
data='20-50', journal='5-20')
p = proposal.Proposal([], ratio=2, db_ratio=2, data="20-50", journal="5-20")
self.check_proposal_init(p, 2, 2, 20, 50, 5, 20)

with pytest.raises(AssertionError):
proposal.Proposal([], ratio=-3, data='20-50', journal='5-20')
proposal.Proposal([], ratio=2, data='50-20', journal='5-20')
proposal.Proposal([], ratio=2, data='50-60', journal='20-5')
proposal.Proposal([], ratio=-3, data="20-50", journal="5-20")
proposal.Proposal([], ratio=2, data="50-20", journal="5-20")
proposal.Proposal([], ratio=2, data="50-60", journal="20-5")

p = proposal.Proposal(output_helper.cephdisks_output)
assert len(p.nvme) is 1
assert len(p.ssd) is 6
assert len(p.spinner) is 12

def check_proposal_init(self, p, dr, dbr, dmi, dma, jmi, jma):
assert p.data_r is dr, 'data_r not correct'
assert p.db_r is dbr, 'db_r not correct'
assert p.data_max is dma, 'data_max not correct'
assert p.data_min is dmi, 'data_min not correct'
assert p.journal_max is jma, 'journal_max not correct'
assert p.journal_min is jmi, 'journal_min not correct'
assert p.data_r is dr, "data_r not correct"
assert p.db_r is dbr, "db_r not correct"
assert p.data_max is dma, "data_max not correct"
assert p.data_min is dmi, "data_min not correct"
assert p.journal_max is jma, "journal_max not correct"
assert p.journal_min is jmi, "journal_min not correct"

def test_propose_standalone(self, output_helper):
p = proposal.Proposal(output_helper.cephdisks_output)
Expand Down Expand Up @@ -103,8 +100,7 @@ def test_propose(self, output_helper):
assert len(prop) is p.DEFAULT_DATA_R

r = 4
p = proposal.Proposal(output_helper.cephdisks_output, ratio=r,
leftovers=True)
p = proposal.Proposal(output_helper.cephdisks_output, ratio=r, leftovers=True)
expected_len = r + (len(p.ssd) - r)
prop = p._propose(p.ssd, p.nvme)
assert len(prop) is expected_len
Expand All @@ -114,45 +110,42 @@ def test_filter(self, output_helper):
# spinners: 1862 GB
# ssds: 372 GB
# nvme: 745 GB
p = proposal.Proposal(output_helper.cephdisks_output, ratio=3,
data='500')
filtered = p._filter(p.spinner, 'data')
p = proposal.Proposal(output_helper.cephdisks_output, ratio=3, data="500")
filtered = p._filter(p.spinner, "data")
assert len(filtered) is len(p.spinner)
filtered = p._filter(p.ssd, 'data')
filtered = p._filter(p.ssd, "data")
assert len(filtered) is 0

p = proposal.Proposal(output_helper.cephdisks_output, ratio=3,
data='500-800')
filtered = p._filter(p.spinner, 'data')
p = proposal.Proposal(output_helper.cephdisks_output, ratio=3, data="500-800")
filtered = p._filter(p.spinner, "data")
assert len(filtered) is 0
filtered = p._filter(p.ssd, 'data')
filtered = p._filter(p.ssd, "data")
assert len(filtered) is 0
filtered = p._filter(p.nvme, 'data')
filtered = p._filter(p.nvme, "data")
assert len(filtered) is len(p.nvme)

p = proposal.Proposal(output_helper.cephdisks_output, ratio=3,
journal='500-800')
filtered = p._filter(p.ssd, 'journal')
p = proposal.Proposal(
output_helper.cephdisks_output, ratio=3, journal="500-800"
)
filtered = p._filter(p.ssd, "journal")
assert len(filtered) is 0
filtered = p._filter(p.nvme, 'journal')
filtered = p._filter(p.nvme, "journal")
assert len(filtered) is len(p.nvme)

def test_create(self, output_helper):
p = proposal.Proposal(output_helper.cephdisks_output)
prop = p.create()
assert len(prop['standalone']) is (len(p.ssd) + len(p.spinner) +
len(p.nvme))
assert len(prop['ssd-spinner']) is p.DEFAULT_DATA_R * 2
assert len(prop['nvme-ssd-spinner']) is 0
assert len(prop['nvme-ssd']) is p.DEFAULT_DATA_R
assert len(prop['nvme-spinner']) is p.DEFAULT_DATA_R
assert len(prop["standalone"]) is (len(p.ssd) + len(p.spinner) + len(p.nvme))
assert len(prop["ssd-spinner"]) is p.DEFAULT_DATA_R * 2
assert len(prop["nvme-ssd-spinner"]) is 0
assert len(prop["nvme-ssd"]) is p.DEFAULT_DATA_R
assert len(prop["nvme-spinner"]) is p.DEFAULT_DATA_R


def replace_disk(self, type='hdd', ratio=2):
def replace_disk(self, type="hdd", ratio=2):
# idx 0-11 -> HDD
# idx 12-17 -> SSD
# idx 18 -> NVME
wal_db_replaced = None
wal_db_replaced = dict()
hwinfo_out = OutputHelper().cephdisks_output
p = proposal.Proposal(OutputHelper().cephdisks_output, ratio=ratio)
old_prop = p.create()
Expand All @@ -170,42 +163,45 @@ def replace_disk(self, type='hdd', ratio=2):
new_p = proposal.Proposal(hwinfo_out_new)
new_prop = new_p.create()

for prop_name, prop in old_prop.items():
for prop_name, prop in old_prop.items():
for disk_set in old_prop[prop_name]:
# ensure that its a proposal with dedicated wal/db
if disk_set.keys()[0] in replaced_hdd['Device Files']:
if prop_name in ['ssd-spinner', 'nvme-ssd-spinner', 'nvme-ssd', 'nvme-spinner']:
wal_db_replaced = disk_set.values()[0]
break
if disk_set.keys()[0] in replaced_hdd["Device Files"]:
if prop_name in [
"ssd-spinner",
"nvme-ssd-spinner",
"nvme-ssd",
"nvme-spinner",
]:
wal_db_replaced[prop_name] = disk_set.values()[0]

return old_prop, new_prop, replaced_hdd, wal_db_replaced

def is_deterministic(self, replaced_disk):
old_prop = replaced_disk[0]
new_prop = replaced_disk[1]
replaced_hdd = replaced_disk[2]
wal_db_replaced = replaced_disk[3]

results = list()
for prop_name, prop in new_prop.items():
for disk_set in old_prop[prop_name]:
matching_disk_from_old_prop = [x for x in prop if disk_set == x]
osd_disk = disk_set.keys()[0]
wal_db = disk_set.values()[0]
# iterate over old proposal
# find disk in new proposal
# compare wal-db mapping

if not matching_disk_from_old_prop and osd_disk not in replaced_hdd['Device Files']:
if 'GENERATED' in osd_disk:
if wal_db != wal_db_replaced:
return False, matching_disk_from_old_prop, osd_disk, wal_db, wal_db_replaced

if matching_disk_from_old_prop:
assert osd_disk == matching_disk_from_old_prop[0].keys()[0]
assert wal_db == matching_disk_from_old_prop[0].values()[0]
return True, [], osd_disk, wal_db, wal_db_replaced

@pytest.mark.parametrize('execution_number', range(1, 1000))
for new_disk_set in prop:
matching_old_disk_set = [
x for x in old_prop[prop_name] if x == new_disk_set
]
osd_disk = new_disk_set.keys()[0]
wal_db = new_disk_set.values()[0]
if matching_old_disk_set:
assert osd_disk == matching_old_disk_set[0].keys()[0]
assert wal_db == matching_old_disk_set[0].values()[0]
if "GENERATED" in osd_disk:
if prop_name != "standalone":
assert wal_db == wal_db_replaced[prop_name]

for res in results:
assert res is True
return True, [], osd_disk, wal_db, wal_db_replaced

@pytest.mark.parametrize("execution_number", range(1, 1000))
def test_determ_hdd(self, execution_number, replaced_disk_hdd):
"""
This test tries to confirm determinism in profile.generate
Expand Down Expand Up @@ -247,10 +243,12 @@ def test_determ_hdd(self, execution_number, replaced_disk_hdd):
:param replaced_disk_hdd:
:return:
"""
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(replaced_disk_hdd)
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(
replaced_disk_hdd
)
assert ret is True

@pytest.mark.parametrize('execution_number', range(1, 1000))
@pytest.mark.parametrize("execution_number", range(1, 1000))
def test_determ_ssd(self, execution_number, replaced_disk_ssd):
"""
See docstring of test_determ_hdd.
Expand All @@ -259,10 +257,12 @@ def test_determ_ssd(self, execution_number, replaced_disk_ssd):
:param replaced_disk_ssd:
:return:
"""
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(replaced_disk_ssd)
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(
replaced_disk_ssd
)
assert ret is True

@pytest.mark.parametrize('execution_number', range(1, 1000))
@pytest.mark.parametrize("execution_number", range(1, 1000))
def test_determ_hdd_ratio_4(self, execution_number, replaced_disk_hdd_ratio_4):
"""
See docstring of test_determ_hdd.
Expand All @@ -271,10 +271,12 @@ def test_determ_hdd_ratio_4(self, execution_number, replaced_disk_hdd_ratio_4):
:param replaced_disk_ssd:
:return:
"""
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(replaced_disk_hdd_ratio_4)
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(
replaced_disk_hdd_ratio_4
)
assert ret is True

@pytest.mark.parametrize('execution_number', range(1, 1000))
@pytest.mark.parametrize("execution_number", range(1, 1000))
def test_determ_nvme(self, execution_number, replaced_disk_nvme):
"""
See docstring of test_determ_hdd.
Expand All @@ -283,5 +285,7 @@ def test_determ_nvme(self, execution_number, replaced_disk_nvme):
:param replaced_disk_nvme:
:return:
"""
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(replaced_disk_nvme)
ret, found, osd_disk, wal_db, wal_db_replaced = self.is_deterministic(
replaced_disk_nvme
)
assert ret is True

0 comments on commit eb18e64

Please sign in to comment.