예제 #1
0
def fake_spec_obj(remove_id=False):
    ctxt = context.RequestContext('fake', 'fake')
    req_obj = objects.RequestSpec(ctxt)
    if not remove_id:
        req_obj.id = 42
    req_obj.instance_uuid = uuidutils.generate_uuid()
    req_obj.image = IMAGE_META
    req_obj.numa_topology = INSTANCE_NUMA_TOPOLOGY
    req_obj.pci_requests = PCI_REQUESTS
    req_obj.flavor = fake_flavor.fake_flavor_obj(ctxt)
    req_obj.retry = objects.SchedulerRetries()
    req_obj.limits = objects.SchedulerLimits()
    req_obj.instance_group = objects.InstanceGroup(uuid=uuids.instgroup)
    req_obj.project_id = 'fake'
    req_obj.user_id = 'fake-user'
    req_obj.num_instances = 1
    req_obj.availability_zone = None
    req_obj.ignore_hosts = ['host2', 'host4']
    req_obj.force_hosts = ['host1', 'host3']
    req_obj.force_nodes = ['node1', 'node2']
    req_obj.scheduler_hints = {'hint': ['over-there']}
    req_obj.requested_destination = None
    # This should never be a changed field
    req_obj.obj_reset_changes(['id'])
    return req_obj
예제 #2
0
 def setUp(self):
     super(MigrationTaskTestCase, self).setUp()
     self.user_id = 'fake'
     self.project_id = 'fake'
     self.context = FakeContext(self.user_id, self.project_id)
     inst = fake_instance.fake_db_instance(image_ref='image_ref')
     self.instance = objects.Instance._from_db_object(
         self.context, objects.Instance(), inst, [])
     self.instance.system_metadata = {'image_hw_disk_bus': 'scsi'}
     self.flavor = fake_flavor.fake_flavor_obj(self.context)
     self.flavor.extra_specs = {'extra_specs': 'fake'}
     self.request_spec = {
         'instance_type': obj_base.obj_to_primitive(self.flavor),
         'instance_properties': {},
         'image': 'image'
     }
     self.hosts = [dict(host='host1', nodename=None, limits={})]
     self.filter_properties = {
         'limits': {},
         'retry': {
             'num_attempts': 1,
             'hosts': [['host1', None]]
         }
     }
     self.reservations = []
     self.clean_shutdown = True
예제 #3
0
 def setUp(self):
     super(ComputeRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     self.fake_flavor_obj = fake_flavor.fake_flavor_obj(self.context)
     self.fake_flavor = jsonutils.to_primitive(self.fake_flavor_obj)
     instance_attr = {
         'host': 'fake_host',
         'instance_type_id': self.fake_flavor_obj['id'],
         'instance_type': self.fake_flavor_obj
     }
     self.fake_instance_obj = fake_instance.fake_instance_obj(
         self.context, **instance_attr)
     self.fake_instance = jsonutils.to_primitive(self.fake_instance_obj)
     self.fake_volume_bdm = objects_block_dev.BlockDeviceMapping(
         **fake_block_device.FakeDbBlockDeviceDict(
             {
                 'source_type': 'volume',
                 'destination_type': 'volume',
                 'instance_uuid': self.fake_instance_obj.uuid,
                 'volume_id': 'fake-volume-id'
             }))
     # FIXME(melwitt): Temporary while things have no mappings
     self.patcher1 = mock.patch('nova.objects.InstanceMapping.'
                                'get_by_instance_uuid')
     self.patcher2 = mock.patch('nova.objects.HostMapping.get_by_host')
     mock_inst_mapping = self.patcher1.start()
     mock_host_mapping = self.patcher2.start()
     mock_inst_mapping.side_effect = exception.InstanceMappingNotFound(
         uuid=self.fake_instance_obj.uuid)
     mock_host_mapping.side_effect = exception.HostMappingNotFound(
         name=self.fake_instance_obj.host)
예제 #4
0
    def test_from_components(self):
        ctxt = context.RequestContext('fake-user', 'fake-project')
        destination = objects.Destination(host='foo')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {
            'id': uuids.image_id,
            'properties': {
                'mappings': []
            },
            'status': 'fake-status',
            'location': 'far-away'
        }
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'requested_destination': destination}
        instance_group = None

        spec = objects.RequestSpec.from_components(
            ctxt, instance.uuid, image, flavor, instance.numa_topology,
            instance.pci_requests, filter_properties, instance_group,
            instance.availability_zone, objects.SecurityGroupList())
        # Make sure that all fields are set using that helper method
        skip = ['id', 'network_metadata', 'is_bfv']
        for field in [f for f in spec.obj_fields if f not in skip]:
            self.assertTrue(spec.obj_attr_is_set(field),
                            'Field: %s is not set' % field)
        # just making sure that the context is set by the method
        self.assertEqual(ctxt, spec._context)
        self.assertEqual(destination, spec.requested_destination)
예제 #5
0
    def setUp(self):
        super(FlavorAccessPolicyTest, self).setUp()
        self.controller = flavor_access.FlavorActionController()
        self.controller_index = flavor_access.FlavorAccessController()
        self.req = fakes.HTTPRequest.blank('')
        self.mock_get = self.useFixture(
            fixtures.MockPatch('nova.api.openstack.common.get_flavor')).mock
        uuid = uuids.fake_id
        self.flavor = fake_flavor.fake_flavor_obj(self.project_member_context,
                                                  id=1,
                                                  uuid=uuid,
                                                  project_id=self.project_id,
                                                  is_public=False)
        self.mock_get.return_value = self.flavor
        self.stub_out('nova.api.openstack.identity.verify_project_id',
                      lambda ctx, project_id: True)
        self.stub_out('nova.objects.flavor._get_projects_from_db',
                      lambda context, flavorid: [])

        # With legacy rule and no scope checks, all admin is able to
        # add/remove flavor access to a tenant.
        self.admin_authorized_contexts = [
            self.legacy_admin_context, self.system_admin_context,
            self.project_admin_context
        ]

        # With legacy rule, anyone can access flavor access info.
        self.admin_index_authorized_contexts = self.all_contexts
예제 #6
0
 def setUp(self):
     super(MigrationTaskTestCase, self).setUp()
     self.user_id = 'fake'
     self.project_id = 'fake'
     self.context = FakeContext(self.user_id, self.project_id)
     self.flavor = fake_flavor.fake_flavor_obj(self.context)
     self.flavor.extra_specs = {'extra_specs': 'fake'}
     inst = fake_instance.fake_db_instance(image_ref='image_ref',
                                           instance_type=self.flavor)
     inst_object = objects.Instance(
         flavor=self.flavor,
         numa_topology=None,
         pci_requests=None,
         system_metadata={'image_hw_disk_bus': 'scsi'})
     self.instance = objects.Instance._from_db_object(
         self.context, inst_object, inst, [])
     self.request_spec = objects.RequestSpec(image=objects.ImageMeta())
     self.hosts = [dict(host='host1', nodename=None, limits={})]
     self.filter_properties = {
         'limits': {},
         'retry': {
             'num_attempts': 1,
             'hosts': [['host1', None]]
         }
     }
     self.reservations = []
     self.clean_shutdown = True
예제 #7
0
파일: test_rpcapi.py 프로젝트: klmitch/nova
 def setUp(self):
     super(ComputeRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     self.fake_flavor_obj = fake_flavor.fake_flavor_obj(self.context)
     self.fake_flavor = jsonutils.to_primitive(self.fake_flavor_obj)
     instance_attr = {'host': 'fake_host',
                      'instance_type_id': self.fake_flavor_obj['id'],
                      'instance_type': self.fake_flavor_obj}
     self.fake_instance_obj = fake_instance.fake_instance_obj(self.context,
                                                **instance_attr)
     self.fake_instance = jsonutils.to_primitive(self.fake_instance_obj)
     self.fake_volume_bdm = objects_block_dev.BlockDeviceMapping(
             **fake_block_device.FakeDbBlockDeviceDict(
                 {'source_type': 'volume', 'destination_type': 'volume',
                  'instance_uuid': self.fake_instance_obj.uuid,
                  'volume_id': 'fake-volume-id'}))
     # FIXME(melwitt): Temporary while things have no mappings
     self.patcher1 = mock.patch('nova.objects.InstanceMapping.'
                                'get_by_instance_uuid')
     self.patcher2 = mock.patch('nova.objects.HostMapping.get_by_host')
     mock_inst_mapping = self.patcher1.start()
     mock_host_mapping = self.patcher2.start()
     mock_inst_mapping.side_effect = exception.InstanceMappingNotFound(
             uuid=self.fake_instance_obj.uuid)
     mock_host_mapping.side_effect = exception.HostMappingNotFound(
             name=self.fake_instance_obj.host)
예제 #8
0
    def test_from_components_with_port_resource_request(self, ):
        ctxt = context.RequestContext(fakes.FAKE_USER_ID,
                                      fakes.FAKE_PROJECT_ID)
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {
            'id': uuids.image_id,
            'properties': {
                'mappings': []
            },
            'status': 'fake-status',
            'location': 'far-away'
        }
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}

        rg = request_spec.RequestGroup()

        spec = objects.RequestSpec.from_components(ctxt,
                                                   instance.uuid,
                                                   image,
                                                   flavor,
                                                   instance.numa_topology,
                                                   instance.pci_requests,
                                                   filter_properties,
                                                   None,
                                                   instance.availability_zone,
                                                   port_resource_requests=[rg])

        self.assertListEqual([rg], spec.requested_resources)
예제 #9
0
    def test_from_components(self):
        ctxt = context.RequestContext('fake-user', 'fake-project')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {
            'id': uuids.image_id,
            'properties': {
                'mappings': []
            },
            'status': 'fake-status',
            'location': 'far-away'
        }
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {}
        instance_group = None

        spec = objects.RequestSpec.from_components(
            ctxt, instance.uuid, image, flavor, instance.numa_topology,
            instance.pci_requests, filter_properties, instance_group,
            instance.availability_zone)
        # Make sure that all fields are set using that helper method
        for field in [f for f in spec.obj_fields if f != 'id']:
            self.assertEqual(True, spec.obj_attr_is_set(field),
                             'Field: %s is not set' % field)
        # just making sure that the context is set by the method
        self.assertEqual(ctxt, spec._context)
예제 #10
0
    def setUp(self):
        super(MigrationTaskTestCase, self).setUp()
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = FakeContext(self.user_id, self.project_id)
        self.flavor = fake_flavor.fake_flavor_obj(self.context)
        self.flavor.extra_specs = {'extra_specs': 'fake'}
        inst = fake_instance.fake_db_instance(image_ref='image_ref',
                                              instance_type=self.flavor)
        inst_object = objects.Instance(
            flavor=self.flavor,
            numa_topology=None,
            pci_requests=None,
            system_metadata={'image_hw_disk_bus': 'scsi'})
        self.instance = objects.Instance._from_db_object(
            self.context, inst_object, inst, [])
        self.request_spec = objects.RequestSpec(image=objects.ImageMeta())
        self.host_lists = [[objects.Selection(service_host="host1",
                nodename="node1", cell_uuid=uuids.cell1)]]
        self.filter_properties = {'limits': {}, 'retry': {'num_attempts': 1,
                                  'hosts': [['host1', 'node1']]}}
        self.reservations = []
        self.clean_shutdown = True

        _p = mock.patch('nova.compute.utils.heal_reqspec_is_bfv')
        self.heal_reqspec_is_bfv_mock = _p.start()
        self.addCleanup(_p.stop)

        _p = mock.patch('nova.objects.RequestSpec.ensure_network_metadata')
        self.ensure_network_metadata_mock = _p.start()
        self.addCleanup(_p.stop)
예제 #11
0
def fake_spec_obj(remove_id=False):
    ctxt = context.RequestContext('fake', 'fake')
    req_obj = objects.RequestSpec(ctxt)
    if not remove_id:
        req_obj.id = 42
    req_obj.instance_uuid = uuidutils.generate_uuid()
    req_obj.image = IMAGE_META
    req_obj.numa_topology = INSTANCE_NUMA_TOPOLOGY
    req_obj.pci_requests = PCI_REQUESTS
    req_obj.flavor = fake_flavor.fake_flavor_obj(ctxt)
    req_obj.retry = objects.SchedulerRetries()
    req_obj.limits = objects.SchedulerLimits()
    req_obj.instance_group = objects.InstanceGroup(uuid=uuids.instgroup)
    req_obj.project_id = 'fake'
    req_obj.user_id = 'fake-user'
    req_obj.num_instances = 1
    req_obj.availability_zone = None
    req_obj.ignore_hosts = ['host2', 'host4']
    req_obj.force_hosts = ['host1', 'host3']
    req_obj.force_nodes = ['node1', 'node2']
    req_obj.scheduler_hints = {'hint': ['over-there']}
    req_obj.requested_destination = None
    # This should never be a changed field
    req_obj.obj_reset_changes(['id'])
    return req_obj
 def get_flavor_extra_specs(context, flavor_id):
     return fake_flavor.fake_flavor_obj(
         self.project_member_context,
         id=1,
         uuid=uuids.fake_id,
         project_id=self.project_id,
         is_public=False,
         extra_specs={'hw:cpu_policy': 'shared'},
         expected_attrs='extra_specs')
    def setUp(self):
        super(FlavorAccessPolicyTest, self).setUp()
        self.controller = flavor_access.FlavorActionController()
        self.controller_index = flavor_access.FlavorAccessController()
        self.req = fakes.HTTPRequest.blank('')
        self.mock_get = self.useFixture(
            fixtures.MockPatch('nova.api.openstack.common.get_flavor')).mock
        uuid = uuids.fake_id
        self.flavor = fake_flavor.fake_flavor_obj(self.project_member_context,
                                                  id=1,
                                                  uuid=uuid,
                                                  project_id=self.project_id,
                                                  is_public=False)
        self.mock_get.return_value = self.flavor
        self.stub_out('nova.api.openstack.identity.verify_project_id',
                      lambda ctx, project_id: True)
        self.stub_out('nova.objects.flavor._get_projects_from_db',
                      lambda context, flavorid: [])

        # Check that admin is able to add/remove flavor access
        # to a tenant.
        self.admin_authorized_contexts = [
            self.legacy_admin_context, self.system_admin_context,
            self.project_admin_context
        ]
        # Check that non-admin is not able to add/remove flavor access
        # to a tenant.
        self.admin_unauthorized_contexts = [
            self.system_member_context, self.system_reader_context,
            self.system_foo_context, self.project_member_context,
            self.other_project_member_context,
            self.other_project_reader_context, self.project_foo_context,
            self.project_reader_context
        ]

        # Check that everyone is able to list flavor access
        # information which is nothing but bug#1867840.
        self.reader_authorized_contexts = [
            self.legacy_admin_context,
            self.system_admin_context,
            self.project_admin_context,
            self.project_member_context,
            self.project_reader_context,
            self.project_foo_context,
            self.system_member_context,
            self.system_reader_context,
            self.system_foo_context,
            self.other_project_member_context,
            self.other_project_reader_context,
        ]

        self.reader_unauthorized_contexts = []
    def setUp(self):
        super(SimpleTenantUsageControllerTestV21, self).setUp()

        self.context = context.RequestContext('fakeuser', 'fake-project')

        self.baseinst = get_fake_db_instance(START, STOP, instance_id=1,
                                             tenant_id=self.context.project_id,
                                             vm_state=vm_states.DELETED)
        # convert the fake instance dict to an object
        flavor = fake_flavor.fake_flavor_obj(self.context, **FAKE_INST_TYPE)
        self.inst_obj = objects.Instance._from_db_object(
            self.context, objects.Instance(), self.baseinst)
        self.inst_obj.flavor = flavor
예제 #15
0
    def test_from_components_without_security_groups(self, mock_pgi):
        # This test makes sure that we populate instance group if not
        # present
        ctxt = context.RequestContext(fakes.FAKE_USER_ID,
                                      fakes.FAKE_PROJECT_ID)
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': uuids.image_id, 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}

        spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, None, instance.availability_zone)
        self.assertNotIn('security_groups', spec)
예제 #16
0
    def test_from_components_without_security_groups(self, mock_pgi):
        # This test makes sure that we populate instance group if not
        # present
        ctxt = context.RequestContext(fakes.FAKE_USER_ID,
                                      fakes.FAKE_PROJECT_ID)
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': uuids.image_id, 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}

        spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, None, instance.availability_zone)
        self.assertNotIn('security_groups', spec)
    def test_from_components_without_instance_group(self, mock_pgi):
        # This test makes sure that we populate instance group if not
        # present
        ctxt = context.RequestContext('fake-user', 'fake-project')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': 'fake-image-id', 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}

        objects.RequestSpec.from_components(ctxt, instance, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, None, instance.availability_zone)

        mock_pgi.assert_called_once_with(filter_properties)
예제 #18
0
    def setUp(self):
        super(SimpleTenantUsageControllerTestV21, self).setUp()

        self.context = context.RequestContext('fakeuser', 'fake-project')

        self.baseinst = get_fake_db_instance(START,
                                             STOP,
                                             instance_id=1,
                                             tenant_id=self.context.project_id,
                                             vm_state=vm_states.DELETED)
        # convert the fake instance dict to an object
        flavor = fake_flavor.fake_flavor_obj(self.context, **FAKE_INST_TYPE)
        self.inst_obj = objects.Instance._from_db_object(
            self.context, objects.Instance(), self.baseinst)
        self.inst_obj.flavor = flavor
예제 #19
0
파일: test_rpcapi.py 프로젝트: zaina/nova
 def setUp(self):
     super(ComputeRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     self.fake_flavor_obj = fake_flavor.fake_flavor_obj(self.context)
     self.fake_flavor = jsonutils.to_primitive(self.fake_flavor_obj)
     instance_attr = {'host': 'fake_host',
                      'instance_type_id': self.fake_flavor_obj['id'],
                      'instance_type': self.fake_flavor_obj}
     self.fake_instance_obj = fake_instance.fake_instance_obj(self.context,
                                                **instance_attr)
     self.fake_instance = jsonutils.to_primitive(self.fake_instance_obj)
     self.fake_volume_bdm = objects_block_dev.BlockDeviceMapping(
             **fake_block_device.FakeDbBlockDeviceDict(
                 {'source_type': 'volume', 'destination_type': 'volume',
                  'instance_uuid': self.fake_instance_obj.uuid,
                  'volume_id': 'fake-volume-id'}))
예제 #20
0
 def setUp(self):
     super(ComputeRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     self.fake_flavor_obj = fake_flavor.fake_flavor_obj(self.context)
     self.fake_flavor = jsonutils.to_primitive(self.fake_flavor_obj)
     instance_attr = {'host': 'fake_host',
                      'instance_type_id': self.fake_flavor_obj['id'],
                      'instance_type': self.fake_flavor_obj}
     self.fake_instance_obj = fake_instance.fake_instance_obj(self.context,
                                                **instance_attr)
     self.fake_instance = jsonutils.to_primitive(self.fake_instance_obj)
     self.fake_volume_bdm = objects_block_dev.BlockDeviceMapping(
             **fake_block_device.FakeDbBlockDeviceDict(
                 {'source_type': 'volume', 'destination_type': 'volume',
                  'instance_uuid': self.fake_instance_obj.uuid,
                  'volume_id': 'fake-volume-id'}))
예제 #21
0
    def test_from_components_with_instance_group(self, mock_pgi):
        # This test makes sure that we don't overwrite instance group passed
        # to from_components
        ctxt = context.RequestContext('fake-user', 'fake-project')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': uuids.image_id, 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}
        instance_group = objects.InstanceGroup()

        objects.RequestSpec.from_components(ctxt, instance.uuid, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, instance_group, instance.availability_zone)

        self.assertFalse(mock_pgi.called)
예제 #22
0
    def test_from_components_with_instance_group(self, mock_pgi):
        # This test makes sure that we don't overwrite instance group passed
        # to from_components
        ctxt = context.RequestContext('fake-user', 'fake-project')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': uuids.image_id, 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}
        instance_group = objects.InstanceGroup()

        objects.RequestSpec.from_components(ctxt, instance.uuid, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, instance_group, instance.availability_zone)

        self.assertFalse(mock_pgi.called)
예제 #23
0
    def test_from_components_with_port_resource_request(self, ):
        ctxt = context.RequestContext(fakes.FAKE_USER_ID,
                                      fakes.FAKE_PROJECT_ID)
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': uuids.image_id, 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}

        rg = request_spec.RequestGroup()

        spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, None, instance.availability_zone,
                port_resource_requests=[rg])

        self.assertListEqual([rg], spec.requested_resources)
예제 #24
0
    def test_from_components(self):
        ctxt = context.RequestContext('fake-user', 'fake-project')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': uuids.image_id, 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {}
        instance_group = None

        spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, instance_group, instance.availability_zone)
        # Make sure that all fields are set using that helper method
        for field in [f for f in spec.obj_fields if f != 'id']:
            self.assertEqual(True, spec.obj_attr_is_set(field),
                             'Field: %s is not set' % field)
        # just making sure that the context is set by the method
        self.assertEqual(ctxt, spec._context)
예제 #25
0
 def setUp(self):
     super(MigrationTaskTestCase, self).setUp()
     self.user_id = 'fake'
     self.project_id = 'fake'
     self.context = FakeContext(self.user_id, self.project_id)
     inst = fake_instance.fake_db_instance(image_ref='image_ref')
     self.instance = objects.Instance._from_db_object(
         self.context, objects.Instance(), inst, [])
     self.instance.system_metadata = {'image_hw_disk_bus': 'scsi'}
     self.flavor = fake_flavor.fake_flavor_obj(self.context)
     self.flavor.extra_specs = {'extra_specs': 'fake'}
     self.request_spec = {'instance_type':
                              obj_base.obj_to_primitive(self.flavor),
                          'instance_properties': {},
                          'image': 'image'}
     self.hosts = [dict(host='host1', nodename=None, limits={})]
     self.filter_properties = {'limits': {}, 'retry': {'num_attempts': 1,
                               'hosts': [['host1', None]]}}
     self.reservations = []
     self.clean_shutdown = True
예제 #26
0
    def setUp(self):
        super(MigrationTaskTestCase, self).setUp()
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = FakeContext(self.user_id, self.project_id)
        self.flavor = fake_flavor.fake_flavor_obj(self.context)
        self.flavor.extra_specs = {'extra_specs': 'fake'}
        inst = fake_instance.fake_db_instance(image_ref='image_ref',
                                              instance_type=self.flavor)
        inst_object = objects.Instance(
            flavor=self.flavor,
            numa_topology=None,
            pci_requests=None,
            system_metadata={'image_hw_disk_bus': 'scsi'})
        self.instance = objects.Instance._from_db_object(
            self.context, inst_object, inst, [])
        self.request_spec = objects.RequestSpec(
            image=objects.ImageMeta(properties=objects.ImageMetaProps()),
            flavor=self.flavor)
        self.request_spec.instance_group = None
        self.hosts = [dict(host='host1', nodename=None, limits={})]
        self.filter_properties = {
            'limits': {},
            'retry': {
                'num_attempts': 1,
                'hosts': [['host1', None]]
            }
        }

        self.instance_group = objects.InstanceGroup()
        self.instance_group['metadetails'] = {
            'wrs-sg:best_effort': 'false',
            'wrs-sg:group_size': '2'
        }
        self.instance_group['members'] = ['uuid1', 'uuid2']
        self.instance_group['hosts'] = ['compute1', 'compute2']
        self.instance_group['policies'] = ['anti-affinity']

        self.reservations = []
        self.clean_shutdown = True
예제 #27
0
 def setUp(self):
     super(ComputeRpcAPITestCase, self).setUp()
     self.context = context.get_admin_context()
     self.fake_flavor_obj = fake_flavor.fake_flavor_obj(self.context)
     self.fake_flavor = jsonutils.to_primitive(self.fake_flavor_obj)
     instance_attr = {
         "host": "fake_host",
         "instance_type_id": self.fake_flavor_obj["id"],
         "instance_type": self.fake_flavor_obj,
     }
     self.fake_instance_obj = fake_instance.fake_instance_obj(self.context, **instance_attr)
     self.fake_instance = jsonutils.to_primitive(self.fake_instance_obj)
     self.fake_volume_bdm = objects_block_dev.BlockDeviceMapping(
         **fake_block_device.FakeDbBlockDeviceDict(
             {
                 "source_type": "volume",
                 "destination_type": "volume",
                 "instance_uuid": self.fake_instance_obj.uuid,
                 "volume_id": "fake-volume-id",
             }
         )
     )
예제 #28
0
    def test_from_components(self):
        ctxt = context.RequestContext('fake-user', 'fake-project')
        destination = objects.Destination(host='foo')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {'id': uuids.image_id, 'properties': {'mappings': []},
                 'status': 'fake-status', 'location': 'far-away'}
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'requested_destination': destination}
        instance_group = None

        spec = objects.RequestSpec.from_components(ctxt, instance.uuid, image,
                flavor, instance.numa_topology, instance.pci_requests,
                filter_properties, instance_group, instance.availability_zone,
                objects.SecurityGroupList())
        # Make sure that all fields are set using that helper method
        skip = ['id', 'network_metadata', 'is_bfv']
        for field in [f for f in spec.obj_fields if f not in skip]:
            self.assertTrue(spec.obj_attr_is_set(field),
                            'Field: %s is not set' % field)
        # just making sure that the context is set by the method
        self.assertEqual(ctxt, spec._context)
        self.assertEqual(destination, spec.requested_destination)
예제 #29
0
 def setUp(self):
     super(MigrationTaskTestCase, self).setUp()
     self.user_id = 'fake'
     self.project_id = 'fake'
     self.context = FakeContext(self.user_id, self.project_id)
     self.flavor = fake_flavor.fake_flavor_obj(self.context)
     self.flavor.extra_specs = {'extra_specs': 'fake'}
     inst = fake_instance.fake_db_instance(image_ref='image_ref',
                                           instance_type=self.flavor)
     inst_object = objects.Instance(
         flavor=self.flavor,
         numa_topology=None,
         pci_requests=None,
         system_metadata={'image_hw_disk_bus': 'scsi'})
     self.instance = objects.Instance._from_db_object(
         self.context, inst_object, inst, [])
     self.request_spec = objects.RequestSpec(image=objects.ImageMeta())
     self.hosts = [dict(host='host1', nodename=None, limits={})]
     self.filter_properties = {'limits': {}, 'retry': {'num_attempts': 1,
                               'hosts': [['host1', None]]}}
     self.reservations = []
     self.clean_shutdown = True
예제 #30
0
    def test_from_components_without_instance_group(self, mock_pgi):
        # This test makes sure that we populate instance group if not
        # present
        ctxt = context.RequestContext('fake-user', 'fake-project')
        instance = fake_instance.fake_instance_obj(ctxt)
        image = {
            'id': 'fake-image-id',
            'properties': {
                'mappings': []
            },
            'status': 'fake-status',
            'location': 'far-away'
        }
        flavor = fake_flavor.fake_flavor_obj(ctxt)
        filter_properties = {'fake': 'property'}

        objects.RequestSpec.from_components(ctxt, instance, image, flavor,
                                            instance.numa_topology,
                                            instance.pci_requests,
                                            filter_properties, None,
                                            instance.availability_zone)

        mock_pgi.assert_called_once_with(filter_properties)
예제 #31
0
    def _setup_test_migrate_disk_and_power_off_mocks(self, same_host=False,
                                                     copy_exception=False,
                                                     size_exception=False):
        self._instance = self._get_instance()
        network_info = fake_network.fake_get_instance_nw_info(self.stubs)

        self._instance['root_gb'] = 10

        fake_local_ip = '10.0.0.1'
        if same_host:
            fake_dest_ip = fake_local_ip
        else:
            fake_dest_ip = '10.0.0.2'

        if size_exception:
            flavor = 'm1.tiny'
        else:
            flavor = 'm1.small'

        flavor = db.flavor_get_by_name(self._context, flavor)
        flavor = fake_flavor.fake_flavor_obj(self._context, **flavor)

        if not size_exception:
            fake_root_vhd_path = 'C:\\FakePath\\root.vhd'
            fake_revert_path = os.path.join(self._test_instance_dir, '_revert')

            func = mox.Func(self._check_instance_name)
            vmutils.VMUtils.set_vm_state(func,
                                         constants.HYPERV_VM_STATE_DISABLED)

            self._setup_delete_vm_log_mocks()

            m = vmutils.VMUtils.get_vm_storage_paths(func)
            m.AndReturn(([fake_root_vhd_path], []))

            m = hostutils.HostUtils.get_local_ips()
            m.AndReturn([fake_local_ip])

            m = fake.PathUtils.get_instance_dir(mox.IsA(str))
            m.AndReturn(self._test_instance_dir)

            m = pathutils.PathUtils.get_instance_migr_revert_dir(
                self._instance.name, remove_dir=True, create_dir=True)
            m.AndReturn(fake_revert_path)

            if same_host:
                fake.PathUtils.makedirs(mox.IsA(str))

            m = fake.PathUtils.copy(fake_root_vhd_path, mox.IsA(str))
            if copy_exception:
                m.AndRaise(shutil.Error('Simulated copy error'))
                m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                    mox.IsA(str),
                                                    remove_dir=True)
                m.AndReturn(self._test_instance_dir)
            else:
                fake.PathUtils.move_folder_files(mox.IsA(str),
                                                 mox.IsA(str))
                destroy_disks = True
                if same_host:
                    fake.PathUtils.move_folder_files(mox.IsA(str),
                                                     mox.IsA(str))
                    destroy_disks = False

                self._setup_destroy_mocks(False)

                if destroy_disks:
                    m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                        mox.IsA(str),
                                                        remove_dir=True)
                    m.AndReturn(self._test_instance_dir)

        return (self._instance, fake_dest_ip, network_info, flavor)
예제 #32
0
    def _setup_test_migrate_disk_and_power_off_mocks(self,
                                                     same_host=False,
                                                     copy_exception=False,
                                                     size_exception=False):
        self._instance = self._get_instance()
        network_info = fake_network.fake_get_instance_nw_info(self.stubs)

        self._instance['root_gb'] = 10

        fake_local_ip = '10.0.0.1'
        if same_host:
            fake_dest_ip = fake_local_ip
        else:
            fake_dest_ip = '10.0.0.2'

        if size_exception:
            flavor = 'm1.tiny'
        else:
            flavor = 'm1.small'

        flavor = db.flavor_get_by_name(self._context, flavor)
        flavor = fake_flavor.fake_flavor_obj(self._context, **flavor)

        if not size_exception:
            fake_root_vhd_path = 'C:\\FakePath\\root.vhd'
            fake_revert_path = os.path.join(self._test_instance_dir, '_revert')

            func = mox.Func(self._check_instance_name)
            vmutils.VMUtils.set_vm_state(func,
                                         constants.HYPERV_VM_STATE_DISABLED)

            self._setup_delete_vm_log_mocks()

            m = vmutils.VMUtils.get_vm_storage_paths(func)
            m.AndReturn(([fake_root_vhd_path], []))

            m = hostutils.HostUtils.get_local_ips()
            m.AndReturn([fake_local_ip])

            m = fake.PathUtils.get_instance_dir(mox.IsA(str))
            m.AndReturn(self._test_instance_dir)

            m = pathutils.PathUtils.get_instance_migr_revert_dir(
                self._instance.name, remove_dir=True, create_dir=True)
            m.AndReturn(fake_revert_path)

            if same_host:
                fake.PathUtils.makedirs(mox.IsA(str))

            m = fake.PathUtils.copy(fake_root_vhd_path, mox.IsA(str))
            if copy_exception:
                m.AndRaise(shutil.Error('Simulated copy error'))
                m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                    mox.IsA(str),
                                                    remove_dir=True)
                m.AndReturn(self._test_instance_dir)
            else:
                fake.PathUtils.move_folder_files(mox.IsA(str), mox.IsA(str))
                destroy_disks = True
                if same_host:
                    fake.PathUtils.move_folder_files(mox.IsA(str),
                                                     mox.IsA(str))
                    destroy_disks = False

                self._setup_destroy_mocks(False)

                if destroy_disks:
                    m = fake.PathUtils.get_instance_dir(mox.IsA(str),
                                                        mox.IsA(str),
                                                        remove_dir=True)
                    m.AndReturn(self._test_instance_dir)

        return (self._instance, fake_dest_ip, network_info, flavor)