예제 #1
0
 def test_cannot_find_fixed_ip(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'] = []
     self.assertRaises(exception.InstanceDeployFailure,
                       network.find_fixed_ip, instance, first_net)
예제 #2
0
 def test_spawn_container(self, image_info=None, instance_href=None,
                           network_info=None):
     instance_href = utils.get_test_instance()
     image_info = utils.get_test_image_info(None, instance_href)
     network_info = utils.get_test_network_info()
     self.driver.spawn(self.ctxt, instance_href, image_info,
                       'fake_files', 'fake_password', network_info=network_info)
예제 #3
0
 def test_cannot_find_fixed_ip(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'] = []
     self.assertRaises(exception.InstanceDeployFailure,
                       network.find_fixed_ip, instance, first_net)
예제 #4
0
 def test_unplug_vifs(self, mock_vp):
     node = ironic_utils.get_test_node()
     instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid)
     network_info = utils.get_test_network_info()
     expected_info = {"uuid": network_info[0]["id"]}
     self.driver._unplug_vifs(node, instance, network_info)
     mock_vp.assert_called_once_with(node.uuid, "delete_vnic", args=expected_info)
예제 #5
0
    def test_create_profile(self):
        """Test the create_profile method, Ensure that the correct
           method calls are preformed when creating a container
           profile.
        """
        instance = stubs._fake_instance()
        rescue = False
        network_info = test_utils.get_test_network_info()
        config = mock.Mock()
        with test.nested(
            mock.patch.object(config.LXDContainerConfig,
                              '_create_config'),
            mock.patch.object(config.LXDContainerConfig,
                              '_create_network'),
            mock.patch.object(session.LXDAPISession,
                              'profile_create')

        ) as (
            mock_create_config,
            mock_create_network,
            mock_profile_create
        ):
            (self.assertEqual(None,
                              self.config.create_profile(instance,
                                                         network_info,
                                                         rescue)))
예제 #6
0
 def _get_running_instance(self, obj=True):
     instance_ref = test_utils.get_test_instance(obj=obj)
     network_info = test_utils.get_test_network_info()
     network_info[0]["network"]["subnets"][0]["meta"]["dhcp_server"] = "1.1.1.1"
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt, instance_ref, image_info, [], "herp", network_info=network_info)
     return instance_ref, network_info
예제 #7
0
 def test_destroy_instance_nonexistent(self):
     fake_instance = {
         'id': 42,
         'name': 'I just made this up!',
         'uuid': 'bda5fb9e-b347-40e8-8256-42397848cb00'
     }
     network_info = test_utils.get_test_network_info()
     self.connection.destroy(self.ctxt, fake_instance, network_info)
예제 #8
0
 def test_find_fixed_ip(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'][0]['cidr'] = '10.0.0.0/24'
     first_net['subnets'][0]['ips'][0]['type'] = 'fixed'
     first_net['subnets'][0]['ips'][0]['address'] = '10.0.1.13'
     self.assertEqual('10.0.1.13/24', network.find_fixed_ip(instance,
                                                            first_net))
예제 #9
0
 def test_find_fixed_ip(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'][0]['cidr'] = '10.0.0.0/24'
     first_net['subnets'][0]['ips'][0]['type'] = 'fixed'
     first_net['subnets'][0]['ips'][0]['address'] = '10.0.1.13'
     self.assertEqual('10.0.1.13/24',
                      network.find_fixed_ip(instance, first_net))
예제 #10
0
 def _get_running_instance(self, obj=True):
     instance_ref = test_utils.get_test_instance(obj=obj)
     network_info = test_utils.get_test_network_info()
     network_info[0]['network']['subnets'][0]['meta']['dhcp_server'] = \
         '1.1.1.1'
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt, instance_ref, image_info,
                           [], 'herp', network_info=network_info)
     return instance_ref, network_info
예제 #11
0
    def test_plug_vifs_with_port(self, mock_vp, mock_neutron):
        node = ironic_utils.get_test_node()
        instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid)
        network_info = utils.get_test_network_info()
        mock_neutron.return_value.show_network.return_value = {"network": {"provider:segmentation_id": 600}}

        self.driver._plug_vifs(node, instance, network_info)
        expected_info = {"vlan": 600, "mac": network_info[0]["address"], "uuid": network_info[0]["id"], "pxe": False}
        mock_vp.assert_called_once_with(node.uuid, "add_vnic", args=expected_info)
예제 #12
0
 def _get_running_instance(self, obj=True):
     instance_ref = test_utils.get_test_instance(obj=obj)
     network_info = test_utils.get_test_network_info()
     network_info[0]['network']['subnets'][0]['meta']['dhcp_server'] = \
         '1.1.1.1'
     image_info = test_utils.get_test_image_info(None, instance_ref)
     self.connection.spawn(self.ctxt, instance_ref, image_info,
                           [], 'herp', network_info=network_info)
     return instance_ref, network_info
예제 #13
0
 def test_get_vif_info(self, mock_get_network_ref):
     network_info = utils.get_test_network_info()
     vif_info = vif.get_vif_info('fake_session', 'fake_cluster',
                                 'is_neutron', 'fake_model', network_info)
     expected = [{'iface_id': 'vif-xxx-yyy-zzz',
                  'mac_address': 'fake',
                  'network_name': 'fake',
                  'network_ref': 'fake_ref',
                  'vif_model': 'fake_model'}]
     self.assertEqual(expected, vif_info)
예제 #14
0
 def test_reboot_container(self, image_info=None, instance_href=None,
                            network_info=None):
     reboot_type = "SOFT"
     instance_href = utils.get_test_instance()
     image_info = utils.get_test_image_info(None, instance_href)
     network_info = utils.get_test_network_info()
     self.driver.spawn(self.ctxt, instance_href, image_info,
                       'fake_files', 'fake_password', network_info=network_info)
     self.driver.reboot(self.ctxt, instance_href, network_info,
                        reboot_type)
예제 #15
0
 def test_get_vif_info(self, mock_get_network_ref):
     network_info = utils.get_test_network_info()
     vif_info = vif.get_vif_info('fake_session', 'fake_cluster',
                                 'is_neutron', 'fake_model', network_info)
     expected = [{'iface_id': utils.FAKE_VIF_UUID,
                  'mac_address': utils.FAKE_VIF_MAC,
                  'network_name': utils.FAKE_NETWORK_BRIDGE,
                  'network_ref': 'fake_ref',
                  'vif_model': 'fake_model'}]
     self.assertEqual(expected, vif_info)
예제 #16
0
 def test_get_vif_info(self, mock_get_network_ref):
     network_info = utils.get_test_network_info()
     vif_info = vif.get_vif_info('fake_session', 'fake_cluster',
                                 'is_neutron', 'fake_model', network_info)
     expected = [{'iface_id': utils.FAKE_VIF_UUID,
                  'mac_address': utils.FAKE_VIF_MAC,
                  'network_name': utils.FAKE_NETWORK_BRIDGE,
                  'network_ref': 'fake_ref',
                  'vif_model': 'fake_model'}]
     self.assertEqual(expected, vif_info)
 def test_get_vif_info(self, mock_get_network_ref):
     network_info = utils.get_test_network_info()
     vif_info = vif.get_vif_info('fake_session', 'fake_cluster',
                                 'is_neutron', 'fake_model', network_info)
     expected = [{'iface_id': 'vif-xxx-yyy-zzz',
                  'mac_address': 'fake',
                  'network_name': 'fake',
                  'network_ref': 'fake_ref',
                  'vif_model': 'fake_model'}]
     self.assertEqual(expected, vif_info)
    def _get_network_info(self, network_id=NETWORK_NAME):
        """Gets network_info from the test utils and then change the network id

           which is set to None. This should not not be None as this id is

           same as portgroup name.

           """
        network_info = utils.get_test_network_info(1)
        network_info[0]['network']['id'] = network_id
        return network_info
    def _get_network_info(self, network_id=NETWORK_NAME):
        """Gets network_info from the test utils and then change the network id

           which is set to None. This should not not be None as this id is

           same as portgroup name.

           """
        network_info = utils.get_test_network_info(1)
        network_info[0]['network']['id'] = network_id
        return network_info
예제 #20
0
 def _get_running_instance(self, obj=True):
     instance_ref = utils.get_test_instance(obj=obj)
     network_info = utils.get_test_network_info()
     network_info[0]['network']['subnets'][0]['meta']['dhcp_server'] = \
         '1.1.1.1'
     image_info = utils.get_test_image_object(None, instance_ref)
     image_info.disk_format = 'raw'
     image_info.container_format = 'docker'
     self.connection.spawn(self.ctxt, instance_ref, image_info,
                           [], 'herp', network_info=network_info)
     return instance_ref, network_info
예제 #21
0
 def _get_running_instance(self, obj=True):
     instance_ref = utils.get_test_instance(obj=obj)
     network_info = utils.get_test_network_info()
     network_info[0]['network']['subnets'][0]['meta']['dhcp_server'] = \
         '1.1.1.1'
     image_info = utils.get_test_image_info(None, instance_ref)
     image_info['disk_format'] = 'raw'
     image_info['container_format'] = 'docker'
     self.connection.spawn(self.ctxt, instance_ref, image_info,
                           [], 'herp', network_info=network_info)
     return instance_ref, network_info
예제 #22
0
 def _get_running_instance(self, obj=False, image_name=None, flavor=None):
     instance_ref = utils.get_test_instance(obj=obj, flavor=flavor)
     network_info = utils.get_test_network_info()
     network_info[0]['network']['subnets'][0]['meta']['dhcp_server'] = (
         '1.1.1.1')
     image_info = utils.get_test_image_info(None, instance_ref)
     image_info['disk_format'] = 'raw'
     image_info['container_format'] = 'docker'
     if image_name:
         image_info['name'] = image_name
     self.connection.spawn(self.ctxt, jsonutils.to_primitive(instance_ref),
                           image_info, [], 'herp',
                           network_info=network_info)
     return instance_ref, network_info
예제 #23
0
 def _get_running_instance(self, obj=False, image_name=None, flavor=None):
     instance_ref = utils.get_test_instance(obj=obj, flavor=flavor)
     network_info = utils.get_test_network_info()
     network_info[0]['network']['subnets'][0]['meta']['dhcp_server'] = (
         '1.1.1.1')
     image_info = utils.get_test_image_info(None, instance_ref)
     image_info['disk_format'] = 'raw'
     image_info['container_format'] = 'docker'
     if image_name:
         image_info['name'] = image_name
     self.connection.spawn(self.ctxt,
                           jsonutils.to_primitive(instance_ref),
                           image_info, [],
                           'herp',
                           network_info=network_info)
     return instance_ref, network_info
예제 #24
0
    def test_plug_vifs_with_port(self, mock_address, mock_vp, mock_neutron):
        node = ironic_utils.get_test_node()
        instance = fake_instance.fake_instance_obj(self.ctx,
                                                   node=node.uuid)
        network_info = utils.get_test_network_info()
        mock_neutron.return_value.show_network.return_value = {
            'network': {
                'provider:segmentation_id': 600}}
        mock_address.return_value = ironic_utils.get_test_port(
            extra={'state': 'UP'})

        self.driver._plug_vifs(node, instance, network_info)
        expected_info = {
            'vlan': 600,
            'mac': network_info[0]['address'],
            'uuid': network_info[0]['id'],
            'pxe': False
        }
        mock_vp.assert_called_once_with(node.uuid, 'add_vnic',
                                        args=expected_info)
        mock_address.assert_called_once_with(network_info[0]['address'])
예제 #25
0
 def test_create_container_net_setup_fails(self, mock_plug_vifs):
     self.assertRaises(exception.InstanceDeployFailure,
                       self.test_create_container,
                       network_info=utils.get_test_network_info())
     self.assertEqual(0, len(self.mock_client.containers()))
예제 #26
0
 def test_find_gateway(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'][0]['gateway']['address'] = '10.0.0.1'
     self.assertEqual('10.0.0.1', network.find_gateway(instance, first_net))
예제 #27
0
 def test_find_gateway(self):
     instance = {'uuid': uuid.uuid4()}
     network_info = test_utils.get_test_network_info()
     first_net = network_info[0]['network']
     first_net['subnets'][0]['gateway']['address'] = '10.0.0.1'
     self.assertEqual('10.0.0.1', network.find_gateway(instance, first_net))
예제 #28
0
    def setUp(self, mock_register, mock_service):
        super(ConfigDriveTestCase, self).setUp()
        vm_util.vm_refs_cache_reset()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        self.flags(cluster_name='test_cluster',
                   host_ip='testhostname',
                   host_username='******',
                   host_password='******',
                   use_linked_clone=False,
                   group='vmware')
        self.flags(enabled=False, group='vnc')
        vmwareapi_fake.reset()
        stubs.set_stubs(self)
        nova.tests.unit.image.fake.stub_out_image_service(self)
        self.conn = driver.VMwareVCDriver(fake.FakeVirtAPI)
        self.network_info = utils.get_test_network_info()
        self.node_name = self.conn._nodename
        image_ref = nova.tests.unit.image.fake.get_valid_image_id()
        instance_values = {
            'vm_state': 'building',
            'project_id': 'fake',
            'user_id': 'fake',
            'name': '1',
            'kernel_id': '1',
            'ramdisk_id': '1',
            'mac_addresses': [{
                'address': 'de:ad:be:ef:be:ef'
            }],
            'memory_mb': 8192,
            'flavor': objects.Flavor(vcpus=4, extra_specs={}),
            'instance_type_id': 0,
            'vcpus': 4,
            'root_gb': 80,
            'image_ref': image_ref,
            'host': 'fake_host',
            'task_state': 'scheduling',
            'reservation_id': 'r-3t8muvr0',
            'id': 1,
            'uuid': uuidsentinel.foo,
            'node': self.node_name,
            'metadata': [],
            'expected_attrs': ['system_metadata'],
        }
        self.test_instance = fake_instance.fake_instance_obj(
            self.context, **instance_values)
        self.test_instance.flavor = objects.Flavor(vcpus=4,
                                                   memory_mb=8192,
                                                   root_gb=80,
                                                   ephemeral_gb=0,
                                                   swap=0,
                                                   extra_specs={})

        (image_service,
         image_id) = glance.get_remote_image_service(context, image_ref)
        metadata = image_service.show(context, image_id)
        self.image = objects.ImageMeta.from_dict({
            'id': image_ref,
            'disk_format': 'vmdk',
            'size': int(metadata['size']),
        })

        class FakeInstanceMetadata(object):
            def __init__(self,
                         instance,
                         content=None,
                         extra_md=None,
                         network_info=None,
                         request_context=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(
            fixtures.MonkeyPatch('nova.api.metadata.base.InstanceMetadata',
                                 FakeInstanceMetadata))

        def fake_make_drive(_self, _path):
            pass

        # We can't actually make a config drive v2 because ensure_tree has
        # been faked out
        self.stub_out('nova.virt.configdrive.ConfigDriveBuilder.make_drive',
                      fake_make_drive)

        def fake_upload_iso_to_datastore(iso_path, instance, **kwargs):
            pass

        self.stub_out('nova.virt.vmwareapi.images.upload_iso_to_datastore',
                      fake_upload_iso_to_datastore)
예제 #29
0
 def test_destroy_instance_nonexistent(self):
     fake_instance = test_utils.get_test_instance(obj=True)
     network_info = test_utils.get_test_network_info()
     self.connection.destroy(self.ctxt, fake_instance, network_info)
예제 #30
0
 def test_get_dns_entries(self):
     driver = docker_driver.DockerDriver(object)
     network_info = utils.get_test_network_info()
     self.assertEqual(['0.0.0.0', '0.0.0.0'],
                      driver._extract_dns_entries(network_info))
예제 #31
0
 def test_create_container_net_setup_fails(self, mock_plug_vifs):
     self.assertRaises(exception.InstanceDeployFailure,
                       self.test_create_container,
                       network_info=utils.get_test_network_info())
     self.assertEqual(0, len(self.mock_client.containers()))
예제 #32
0
 def test_ensure_filtering_for_instance(self):
     instance = test_utils.get_test_instance(obj=True)
     network_info = test_utils.get_test_network_info()
     self.connection.ensure_filtering_rules_for_instance(
         instance, network_info)
예제 #33
0
 def test_destroy_instance_nonexistent(self):
     fake_instance = {'id': 42, 'name': 'I just made this up!',
                      'uuid': 'bda5fb9e-b347-40e8-8256-42397848cb00'}
     network_info = test_utils.get_test_network_info()
     self.connection.destroy(self.ctxt, fake_instance, network_info)
예제 #34
0
 def test_ensure_filtering_for_instance(self):
     instance = test_utils.get_test_instance(obj=True)
     network_info = test_utils.get_test_network_info()
     self.connection.ensure_filtering_rules_for_instance(instance,
                                                         network_info)
예제 #35
0
 def test_unfilter_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     self.connection.unfilter_instance(instance_ref, network_info)
예제 #36
0
 def test_destroy_instance_nonexistent(self):
     fake_instance = test_utils.get_test_instance(obj=True)
     network_info = test_utils.get_test_network_info()
     self.connection.destroy(self.ctxt, fake_instance, network_info)
예제 #37
0
 def test_get_dns_entries(self):
     driver = docker_driver.DockerDriver(object)
     network_info = utils.get_test_network_info()
     self.assertEqual(['0.0.0.0', '0.0.0.0'],
                      driver._extract_dns_entries(network_info))
예제 #38
0
 def test_unfilter_instance(self):
     instance_ref = test_utils.get_test_instance()
     network_info = test_utils.get_test_network_info()
     self.connection.unfilter_instance(instance_ref, network_info)
예제 #39
0
    def setUp(self, mock_register, mock_service):
        super(ConfigDriveTestCase, self).setUp()
        vm_util.vm_refs_cache_reset()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        self.flags(cluster_name='test_cluster',
                   host_ip='testhostname',
                   host_username='******',
                   host_password='******',
                   use_linked_clone=False, group='vmware')
        self.flags(enabled=False, group='vnc')
        vmwareapi_fake.reset()
        stubs.set_stubs(self)
        nova.tests.unit.image.fake.stub_out_image_service(self)
        self.conn = driver.VMwareVCDriver(fake.FakeVirtAPI)
        self.network_info = utils.get_test_network_info()
        self.node_name = self.conn._nodename
        image_ref = nova.tests.unit.image.fake.get_valid_image_id()
        instance_values = {
            'vm_state': 'building',
            'project_id': 'fake',
            'user_id': 'fake',
            'name': '1',
            'kernel_id': '1',
            'ramdisk_id': '1',
            'mac_addresses': [{'address': 'de:ad:be:ef:be:ef'}],
            'memory_mb': 8192,
            'flavor': objects.Flavor(vcpus=4, extra_specs={}),
            'instance_type_id': 0,
            'vcpus': 4,
            'root_gb': 80,
            'image_ref': image_ref,
            'host': 'fake_host',
            'task_state': 'scheduling',
            'reservation_id': 'r-3t8muvr0',
            'id': 1,
            'uuid': uuidsentinel.foo,
            'node': self.node_name,
            'metadata': [],
            'expected_attrs': ['system_metadata'],
        }
        self.test_instance = fake_instance.fake_instance_obj(self.context,
                                                             **instance_values)
        self.test_instance.flavor = objects.Flavor(vcpus=4, memory_mb=8192,
                                                   root_gb=80,
                                                   ephemeral_gb=0, swap=0,
                                                   extra_specs={})

        (image_service, image_id) = glance.get_remote_image_service(context,
                                    image_ref)
        metadata = image_service.show(context, image_id)
        self.image = objects.ImageMeta.from_dict({
            'id': image_ref,
            'disk_format': 'vmdk',
            'size': int(metadata['size']),
        })

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None,
                         network_info=None, request_context=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch(
                'nova.api.metadata.base.InstanceMetadata',
                FakeInstanceMetadata))

        def fake_make_drive(_self, _path):
            pass
        # We can't actually make a config drive v2 because ensure_tree has
        # been faked out
        self.stub_out('nova.virt.configdrive.ConfigDriveBuilder.make_drive',
                      fake_make_drive)

        def fake_upload_iso_to_datastore(iso_path, instance, **kwargs):
            pass
        self.stub_out('nova.virt.vmwareapi.images.upload_iso_to_datastore',
                       fake_upload_iso_to_datastore)