def test_big_nid_map_scalable(self): """check big nid mapping is scalable.""" model = Model() model.parse("nid_map: nodes=foo[1-9999] nids=bar[1-9999]@tcp") before = time.time() NidMap.fromlist(model.get('nid_map')) self.assertTrue(time.time() - before < .5)
def test_big_nid_map_scalable(self): """check big nid mapping is scalable.""" model = Model() model.parse("nid_map: nodes=foo[1-9999] nids=bar[1-9999]@tcp") before = time.time() NidMap.fromlist(model.get("nid_map")) self.assertTrue(time.time() - before < 0.5)
def test_match_device_error(self): model = Model() model.parse("""fs_name: nids nid_map: nodes=foo[7] nids=foo[7]@tcp mgt: node=(\<badregexp>""") candidate = [{'node': 'foo7', 'dev': '/dev/sda'}] self.assertRaises(ModelFileValueError, model.get('mgt')[0].match_device, candidate)
def test_match_device_error(self): model = Model() model.parse("""fs_name: nids nid_map: nodes=foo[7] nids=foo[7]@tcp mgt: node=(\<badregexp>""") candidate = [ {'node': 'foo7', 'dev': '/dev/sda'} ] self.assertRaises(ModelFileValueError, model.get('mgt')[0].match_device, candidate)
def test_match_device_missing_prop(self): """check missing property does not match in match_device()""" model = Model() model.parse("""fs_name: nids nid_map: nodes=foo[7] nids=foo[7]@tcp mgt: node=foo7 network=tcp""") candidate = [ {'node': 'foo7', 'dev': '/dev/sda'} ] self.assertEqual(len(model.get('mgt')[0].match_device(candidate)), 0)
def test_match_device_missing_prop(self): """check missing property does not match in match_device()""" model = Model() model.parse("""fs_name: nids nid_map: nodes=foo[7] nids=foo[7]@tcp mgt: node=foo7 network=tcp""") candidate = [{'node': 'foo7', 'dev': '/dev/sda'}] self.assertEqual(len(model.get('mgt')[0].match_device(candidate)), 0)
def test_match_device_simple_pattern(self): """check different values do not match in match_device()""" candidate = [{'node': 'foo7', 'dev': '/dev/sda'}] model = Model() model.parse( textwrap.dedent("""fs_name: match nid_map: nodes=foo8 nids=foo8@tcp mgt: node=foo8""")) self.assertEqual(len(model.get('mgt')[0].match_device(candidate)), 0)
def test_several_spaces(self): model = Model() model.parse("""fs_name: spaces nid_map: nodes=foo[7] nids=foo[7]@tcp mgt: node=foo7 """) self.assertEqual(model.get('fs_name'), 'spaces') self.assertEqual(len(model.elements('nid_map')), 1) self.assertEqual(model.elements('nid_map')[0].as_dict(), { 'nodes': 'foo[7]', 'nids': 'foo[7]@tcp' })
def test_match_device_ignore_index(self): """test match_device() does not try to match index property""" model = Model() model.parse("""fs_name: nids nid_map: nodes=foo[7] nids=foo[7]@tcp ost: node=foo7 index=0""") candidate = [ {'node': 'foo7', 'dev': '/dev/sda'} ] matched = model.get('ost')[0].match_device(candidate) self.assertEqual(len(matched), 1) self.assertEqual(matched[0].get('dev'), '/dev/sda')
def test_match_device_ignore_index(self): """test match_device() does not try to match index property""" model = Model() model.parse("""fs_name: nids nid_map: nodes=foo[7] nids=foo[7]@tcp ost: node=foo7 index=0""") candidate = [{'node': 'foo7', 'dev': '/dev/sda'}] matched = model.get('ost')[0].match_device(candidate) self.assertEqual(len(matched), 1) self.assertEqual(matched[0].get('dev'), '/dev/sda')
def test_several_spaces(self): model = Model() model.parse("""fs_name: spaces nid_map: nodes=foo[7] nids=foo[7]@tcp mgt: node=foo7 """) self.assertEqual(model.get('fs_name'), 'spaces') self.assertEqual(len(model.elements('nid_map')), 1) self.assertEqual( model.elements('nid_map')[0].as_dict(), { 'nodes': 'foo[7]', 'nids': 'foo[7]@tcp' })
def test_diff_client(self): """check diff detects updated clients.""" model = Model() model.parse("""fs_name: diff nid_map: nodes=foo1 nids=foo1@tcp client: node=foo1""") new_m = Model() new_m.parse("""fs_name: diff nid_map: nodes=foo1 nids=foo1@tcp client: node=foo1 mount_options=ro""") added, changed, removed = model.diff(new_m) self.assertEqual(len(added), 0) self.assertEqual(len(removed), 0) self.assertEqual(str(changed), "client:node=foo1 mount_options=ro")
def test_diff_ost(self): """check diff detects updated targets.""" model = Model() model.parse("""fs_name: diff nid_map: nodes=foo1 nids=foo1@tcp ost: node=foo1 dev=/dev/sda ost: node=foo1 dev=/dev/sdc mode=external """) new_m = Model() new_m.parse("""fs_name: diff nid_map: nodes=foo1 nids=foo1@tcp ost: node=foo1 dev=/dev/sdc jdev=/dev/sdd """) added, changed, removed = model.diff(new_m) self.assertEqual(len(added), 0) self.assertEqual(str(removed), "ost:node=foo1 dev=/dev/sda") self.assertEqual(str(changed), "ost:node=foo1 dev=/dev/sdc jdev=/dev/sdd")
def test_folding(self): """config lines are grouped when possible""" model = Model() model.parse( textwrap.dedent(""" fs_name: fold nid_map: nodes=foo[1-2] nids=foo[1-2]@tcp2 client: node=foo1 client: node=foo2 router: node=foo1 router: node=foo2""")) self.assertEqual( str(model), textwrap.dedent(""" fs_name:fold client:node=foo[1-2] router:node=foo[1-2] nid_map:nids=foo[1-2]@tcp2 nodes=foo[1-2]""").lstrip())
def test_2_nid_map_diff_pattern(self): """Model with nid_map with several ranges""" model = Model() model.parse( textwrap.dedent("""fs_name: nids nid_map: nodes=foo[1-2] nids=foo[1-2]@tcp nid_map: nodes=bar[1-9] nids=bar[1-9]@tcp""")) self.assertEqual(len(model.elements('nid_map')), 11) self.assertEqual( model.elements('nid_map')[0].as_dict(), { 'nodes': 'foo1', 'nids': 'foo1@tcp' }) self.assertEqual( model.elements('nid_map')[10].as_dict(), { 'nodes': 'bar9', 'nids': 'bar9@tcp' })
def test_several_nid_map(self): """Model with several nid_map lines.""" model = Model() model.parse("""fs_name: nids nid_map: nodes=foo[1-2] nids=foo[1-2]@tcp nid_map: nodes=foo[7] nids=foo[7]@tcp""") self.assertEqual(len(model.elements('nid_map')), 3) self.assertEqual( model.elements('nid_map')[0].as_dict(), { 'nodes': 'foo1', 'nids': 'foo1@tcp' }) self.assertEqual( model.elements('nid_map')[1].as_dict(), { 'nodes': 'foo2', 'nids': 'foo2@tcp' }) self.assertEqual( model.elements('nid_map')[2].as_dict(), { 'nodes': 'foo7', 'nids': 'foo7@tcp' })
def test_match_device_list_values(self): """check various list content do not match in match_device()""" # Different value count candidate = [{'node': 'foo7', 'ha_node': ['foo8'], 'dev': '/dev/sda'}] model = Model() model.parse( textwrap.dedent("""fs_name: nids nid_map: nodes=foo[7-10] nids=foo[7-10]@tcp mgt: node=foo7 ha_node=foo8 ha_node=foo9""")) self.assertEqual(len(model.get('mgt')[0].match_device(candidate)), 0) # Different list values candidate = [{ 'node': 'foo7', 'ha_node': ['foo7', 'foo8'], 'dev': '/dev/sda' }] model = Model() model.parse( textwrap.dedent("""fs_name: nids nid_map: nodes=foo[7-10] nids=foo[7-10]@tcp mgt: node=foo7 ha_node=foo8 ha_node=foo9""")) self.assertEqual(len(model.get('mgt')[0].match_device(candidate)), 0)