def test_build_ip_constraints(self): # role distribution rsc = { 'grp1': [Host('node1')], 'grp2': [Host('node2')] } # ips informations ips = { 'node1': { 'all_ipv4_addresses': ['ip11', 'ip12'], 'devices': [{'device': 'eth0', 'active': True},{'device': 'eth1', 'active': True}] }, 'node2': { 'all_ipv4_addresses': ['ip21', 'ip21'], 'devices': [{'device': 'eth0', 'active': True},{'device': 'eth1', 'active': True}] } } # the constraints constraint = { 'src': 'grp1', 'dst': 'grp2', 'rate': '10mbit', 'delay': '10ms', 'loss': '0.1%' } constraints = [constraint] ips_with_tc = build_ip_constraints(rsc, ips, constraints) # tc rules are applied on the source only self.assertTrue('tc' in ips_with_tc['node1']) tcs = ips_with_tc['node1']['tc'] # one rule per dest ip and source device self.assertEquals(2*2, len(tcs))
class TestSSH(unittest.TestCase): longMessage = True hosts = [Host('1.2.3.4')] env = {'resultdir': 'foo/bar', 'inventory': 'foo/bar'} def test_wait_ssh_succeed(self): with mock.patch('enos.utils.extra.run_ansible', new_callable=mock.Mock()) as m: m.return_value = None self.assertIsNone(wait_ssh(self.env, interval=0)) def test_wait_ssh_eventually_succeed(self): with mock.patch('enos.utils.extra.run_ansible', new_callable=mock.Mock()) as m: effects = [ EnosUnreachableHostsError(self.hosts) for i in range(1, 10) ] effects.append(None) m.side_effect = effects self.assertIsNone(wait_ssh(self.env, retries=10, interval=0)) def test_wait_ssh_fails(self): with self.assertRaisesRegexp(Exception, 'Maximum retries reached'),\ mock.patch('enos.utils.extra.run_ansible', new_callable=mock.Mock()) as m: m.side_effect = EnosUnreachableHostsError(self.hosts) wait_ssh(self.env, interval=0)
def test_build_roles_one_less_deployed_nodes(self): deployed_nodes = map(lambda x: Host(x), ["a-1", "a-2", "a-3", "a-4", "a-5"]) roles = build_roles(self.config, deployed_nodes, self.byCluster) self.assertEquals(1, len(roles["controller"])) self.assertEquals(1, len(roles["storage"])) self.assertEquals(1, len(roles["compute"])) self.assertEquals(1, len(roles["network"])) self.assertEquals(1, len(roles["util"]))
def test_build_roles_with_topology(self): config = { "topology": { "grp1": { "a": { "control": 1, "network": 1, "util": 1 } }, "grp2": { "a": { "compute": 1, } }, "grp3": { "a": { "compute": 1, } } }, # resources is an aggregated view of the topology "resources": { "a": { "control": 1, "network": 1, "util": 1, "compute": 2 } } } deployed_nodes = map(lambda x: Host(x), ["a-1", "a-2", "a-3", "a-4", "a-5"]) roles = build_roles(config, deployed_nodes, self.byCluster) # Check the sizes self.assertEqual(2, len(roles["compute"])) self.assertEqual(1, len(roles["network"])) self.assertEqual(1, len(roles["control"])) # Check the consistency betwwen groups self.assertListEqual( sorted(roles["grp1"]), sorted(roles["control"] + roles["network"] + roles["util"])) self.assertListEqual(sorted(roles["grp2"] + roles["grp3"]), sorted(roles["compute"]))
def test_build_roles_with_multiple_clusters(self): config = { "resources": { "a": { "controller": 1, "compute" : 2, "network" : 1, "storage" : 1, "util" : 1 }, "b": { "compute": 2 } } } deployed_nodes = map(lambda x: Host(x), ["a-1", "a-2", "a-3", "a-4", "a-5", "a-6", "b-1", "b-2"]) roles = build_roles(config, deployed_nodes, self.byCluster) self.assertEquals(1, len(roles["controller"])) self.assertEquals(1, len(roles["storage"])) self.assertEquals(4, len(roles["compute"])) self.assertEquals(1, len(roles["network"])) self.assertEquals(1, len(roles["util"]))
def test_address_gateway_same_user(self): h = Host("1.2.3.4", user="******", extra={'gateway': '4.3.2.1'}) role = "test" self.assertEqual( "1.2.3.4 ansible_host=1.2.3.4 ansible_ssh_user=foo ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand=\"ssh -W %h:%p -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -l foo 4.3.2.1\"' g5k_role=test", generate_inventory_string(h, role))
def test_address_user(self): h = Host("1.2.3.4", user="******") role = "test" self.assertEqual( "1.2.3.4 ansible_host=1.2.3.4 ansible_ssh_user=foo ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' g5k_role=test", generate_inventory_string(h, role))
def test_address_gateway(self): h = Host("1.2.3.4", extra={'gateway': '4.3.2.1'}) role = "test" self.assertEqual( "1.2.3.4 ansible_host=1.2.3.4 ansible_ssh_common_args='-o StrictHostKeyChecking=no -o ProxyCommand=\"ssh -W %h:%p -o StrictHostKeyChecking=no 4.3.2.1\"' g5k_role=test", generate_inventory_string(h, role))
def test_address_alias(self): h = Host("1.2.3.4", alias="alias") role = "test" self.assertEqual( "alias ansible_host=1.2.3.4 ansible_ssh_common_args='-o StrictHostKeyChecking=no' g5k_role=test", generate_inventory_string(h, role))