def test__add_resources_to_template_no_servers(self, mock_template): self.test_context.keypair_name = "foo-key" self.test_context.secgroup_name = "foo-secgroup" self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b" netattrs = { 'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net' } self.mock_context.name = 'bar' self.test_context.networks = [ model.Network("fool-network", self.mock_context, netattrs) ] self.test_context._add_resources_to_template(mock_template) mock_template.add_keypair.assert_called_with( "foo-key", "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b") mock_template.add_security_group.assert_called_with("foo-secgroup") mock_template.add_network.assert_called_with("bar-fool-network", 'physnet1', None) mock_template.add_router.assert_called_with( "bar-fool-network-router", netattrs["external_network"], "bar-fool-network-subnet") mock_template.add_router_interface.assert_called_with( "bar-fool-network-router-if0", "bar-fool-network-router", "bar-fool-network-subnet")
def test__add_resources_to_template_no_servers(self, mock_template): self.test_context._name = 'ctx' self.test_context._task_id = '1234567890' self.test_context._name_task_id = '{}-{}'.format( self.test_context._name, self.test_context._task_id[:8]) self.test_context.keypair_name = "ctx-key" self.test_context.secgroup_name = "ctx-secgroup" self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b" netattrs = { 'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net' } self.test_context.networks = OrderedDict( {"mynet": model.Network("mynet", self.test_context, netattrs)}) self.test_context._add_resources_to_template(mock_template) mock_template.add_keypair.assert_called_with("ctx-key", "ctx-12345678") mock_template.add_security_group.assert_called_with("ctx-secgroup") mock_template.add_network.assert_called_with("ctx-12345678-mynet", 'physnet1', None, None, None, None) mock_template.add_router.assert_called_with( "ctx-12345678-mynet-router", netattrs["external_network"], "ctx-12345678-mynet-subnet") mock_template.add_router_interface.assert_called_with( "ctx-12345678-mynet-router-if0", "ctx-12345678-mynet-router", "ctx-12345678-mynet-subnet")
def test__add_instance_with_ip_override_invalid_syntax( self, mock_template): network_ports = { 'mgmt': ['mgmt'], 'uplink_0': 'xe0', 'downlink_0': [ { 'xe1': { 'local_ip': '10.44.0.30', 'netmask': '255.255.255.0' } }, ], } attrs = { 'image': 'some-image', 'flavor': 'some-flavor', } test_server = model.Server('foo', self.mock_context, attrs) test_server.network_ports = network_ports context = type("Context", (object, ), {}) # can't use Mock because Mock.name is reserved context.name = "context" networks = [model.Network(n, context, {}) for n in network_ports] with self.assertRaises(SyntaxError): test_server._add_instance(mock_template, 'some-server', networks, 'hints')
def test_construct_no_external_network(self): attrs = {'cidr': '10.0.0.0/24'} test_network = model.Network('foo', self.mock_context, attrs) self.assertEqual(test_network.stack_name, 'bar-foo') self.assertEqual(test_network.subnet_stack_name, 'bar-foo-subnet') self.assertEqual(test_network.subnet_cidr, attrs['cidr']) self.assertIsNone(test_network.router) self.assertIn(test_network, model.Network.list)
def init(self, attrs): super(KubernetesContext, self).init(attrs) networks = attrs.get('networks', {}) self.template = kubernetes.KubernetesTemplate(self.name, attrs) self.ssh_key = '{}-key'.format(self.name) self.key_path = self._get_key_path() self.public_key_path = '{}.pub'.format(self.key_path) self._networks = collections.OrderedDict( (net_name, model.Network(net_name, self, network)) for net_name, network in networks.items())
def test_construct_has_external_network(self): attrs = {'external_network': 'ext_net'} test_network = model.Network('foo', self.mock_context, attrs) exp_router = model.Router('router', 'foo', self.mock_context, 'ext_net') self.assertEqual(test_network.router.stack_name, exp_router.stack_name) self.assertEqual(test_network.router.stack_if_name, exp_router.stack_if_name) self.assertEqual(test_network.router.external_gateway_info, exp_router.external_gateway_info)
def setUp(self): self.mock_context = mock.Mock() self.mock_context.name = 'bar' self.mock_context.keypair_name = 'some-keys' self.mock_context.secgroup_name = 'some-secgroup' self.mock_context.user = "******" netattrs = { 'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net' } self.mock_context.networks = [ model.Network("some-network", self.mock_context, netattrs) ]
def test__add_instance_with_ip_override(self, mock_template): network_ports = { 'mgmt': ['mgmt'], 'uplink_0': [ { 'xe0': { 'local_ip': '10.44.0.20', 'netmask': '255.255.255.0' } }, ], 'downlink_0': [ { 'xe1': { 'local_ip': '10.44.0.30', 'netmask': '255.255.255.0' } }, ], } attrs = { 'image': 'some-image', 'flavor': 'some-flavor', } test_server = model.Server('foo', self.mock_context, attrs) test_server.network_ports = network_ports context = type("Context", (object, ), {}) # can't use Mock because Mock.name is reserved context.name = "context" networks = [model.Network(n, context, {}) for n in network_ports] test_server._add_instance(mock_template, 'some-server', networks, 'hints') self.assertEqual( test_server.ports, { 'downlink_0': [{ 'port': 'xe1', 'stack_name': 'some-server-xe1-port' }], 'mgmt': [{ 'port': 'mgmt', 'stack_name': 'some-server-mgmt-port' }], 'uplink_0': [{ 'port': 'xe0', 'stack_name': 'some-server-xe0-port' }] })
def test_construct_gateway_ip_is_absent(self): attrs = {} test_network = model.Network('foo', self.mock_context, attrs) self.assertIsNone(test_network.gateway_ip)
def test_construct_gateway_ip_is_none(self): attrs = {'gateway_ip': None} test_network = model.Network('foo', self.mock_context, attrs) self.assertEqual(test_network.gateway_ip, 'null')
def test_has_no_route_to(self): attrs = {} test_network = model.Network('foo', self.mock_context, attrs) self.assertFalse(test_network.has_route_to('ext_net'))
def test_has_route_to(self): attrs = {'external_network': 'ext_net'} test_network = model.Network('foo', self.mock_context, attrs) self.assertTrue(test_network.has_route_to('ext_net'))