Пример #1
0
 def _setup(self):
     self.controller = networks_v21.NetworkController(self.fake_network_api)
     self.associate_controller = networks_associate_v21\
         .NetworkAssociateActionController(self.fake_network_api)
     self.neutron_assoc_ctrl = (
         networks_associate_v21.NetworkAssociateActionController(
             neutron.API()))
     self.req = fakes.HTTPRequest.blank('')
Пример #2
0
 def _setup(self):
     ext_mgr = extensions.ExtensionManager()
     ext_mgr.extensions = {'os-extended-networks': 'fake'}
     self.controller = networks.NetworkController(self.fake_network_api,
                                                  ext_mgr)
     self.neutron_ctrl = networks.NetworkController(
         neutron.API(skip_policy_check=False))
     self.req = fakes.HTTPRequest.blank('', use_admin_context=True)
Пример #3
0
 def _setup(self):
     ext_mgr = extensions.ExtensionManager()
     ext_mgr.extensions = {'os-extended-networks': 'fake'}
     self.controller = networks.NetworkController(self.fake_network_api,
                                                  ext_mgr)
     self.associate_controller = networks_associate\
         .NetworkAssociateActionController(self.fake_network_api)
     self.neutron_assoc_ctrl = (
         networks_associate.NetworkAssociateActionController(
             neutron.API(skip_policy_check=False)))
    def test_delete_security_group_in_use(self):
        sg = self._create_sg_template().get('security_group')
        self._create_network()
        fake_instance = {'project_id': 'fake_tenant',
                         'availability_zone': 'zone_one',
                         'security_groups': [],
                         'uuid': str(uuid.uuid4()),
                         'display_name': 'test_instance'}
        neutron = neutron_api.API()
        neutron.allocate_for_instance(context.get_admin_context(),
                                      fake_instance,
                                      security_groups=[sg['id']])

        req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/%s'
                                      % sg['id'])
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, sg['id'])
Пример #5
0
    def test_delete_security_group_in_use(self):
        sg = self._create_sg_template().get('security_group')
        self._create_network()
        db_inst = fakes.stub_instance(id=1, nw_cache=[], security_groups=[])
        _context = context.get_admin_context()
        instance = instance_obj.Instance._from_db_object(
            _context, instance_obj.Instance(), db_inst,
            expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS)
        neutron = neutron_api.API()
        with mock.patch.object(nova.db, 'instance_get_by_uuid',
                               return_value=db_inst):
            neutron.allocate_for_instance(_context, instance,
                                          security_groups=[sg['id']])

        req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/%s'
                                      % sg['id'])
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, sg['id'])
 def _setup(self):
     self.controller = networks_v21.NetworkController(self.fake_network_api)
     self.neutron_ctrl = networks_v21.NetworkController(neutron.API())
     self.req = fakes.HTTPRequest.blank('',
                                        project_id=fakes.FAKE_PROJECT_ID)
Пример #7
0
 def _setup(self):
     self.controller = networks_v21.NetworkController(self.fake_network_api)
     self.neutron_ctrl = networks_v21.NetworkController(
         neutron.API(skip_policy_check=True))
 def _setup(self):
     self.controller = networks_v21.NetworkController(self.fake_network_api)
     self.neutron_ctrl = networks_v21.NetworkController(
         neutron.API(skip_policy_check=True))
     self.req = fakes.HTTPRequest.blank('')
Пример #9
0
    def _test_schedule_provider_network(self, scheduler_hints,
                         mock_get_all, mock_by_host, mock_get_by_binary,
                         mock_get_all_states):

        vif_dict = dict(vif_model='virtio')
        fake_vif1 = fake_network_cache_model.new_vif(vif_dict)
        fake_vif2 = fake_network_cache_model.new_vif(vif_dict)
        fake_vif2['network']['id'] = 2
        fake_vif3 = fake_network_cache_model.new_vif(vif_dict)
        fake_vif3['network']['id'] = 3
        fake_vif4 = fake_network_cache_model.new_vif(vif_dict)
        fake_vif4['network']['id'] = 4
        fake_nw_info = network_model.NetworkInfo([fake_vif1, fake_vif2,
                                                  fake_vif3, fake_vif4])
        fake_info_cache = objects.InstanceInfoCache(network_info=fake_nw_info)
        fake_inst = objects.Instance(info_cache=fake_info_cache)
        fake_build_req = objects.BuildRequest(instance=fake_inst)

        @staticmethod
        def _fake_get_by_instance_uuid(context, instance_uuid):
            return fake_build_req

        @staticmethod
        def _fake_get_by_uuid(context, instance_uuid):
            return fake_inst

        self.stub_out('nova.objects.BuildRequest.get_by_instance_uuid',
                      _fake_get_by_instance_uuid)
        self.stub_out('nova.objects.Instance.get_by_uuid', _fake_get_by_uuid)

        def _fake_net_get_dict(context, network_uuid):
            if network_uuid == 1:
                return {'provider:physical_network': 'physnet0'}
            elif network_uuid == 2:
                return {'provider:physical_network': 'physnet1'}
            elif network_uuid == 3:
                return {'provider:physical_network': 'physnet1'}
            else:
                return {}

        from nova.network.neutronv2 import api as neutronapi
        self.driver.network_api = neutronapi.API()
        self.stubs.Set(self.driver.network_api, 'get_dict',
                      _fake_net_get_dict)

        spec_obj = objects.RequestSpec(
            num_instances=1,
            flavor=objects.Flavor(memory_mb=512,
                                  root_gb=512,
                                  ephemeral_gb=0,
                                  vcpus=1,
                                  extra_specs={}),
            project_id=1,
            os_type='Linux',
            instance_uuid='00000000-aaaa-bbbb-cccc-000000000000',
            pci_requests=None,
            numa_topology=None,
            instance_group=None,
            scheduler_hints=scheduler_hints,
            # WRS extension
            display_name = 'fake-vm',
            name = 'instance-00000001',
            image=objects.ImageMeta(properties=objects.ImageMetaProps()))

        host_state = mock.Mock(spec=host_manager.HostState,
            host=mock.sentinel.host, uuid=uuids.cn1, numa_topology=None)
        all_host_states = [host_state]
        mock_get_all_states.return_value = all_host_states

        instance_uuids = [uuids.instance]
        allocs = \
           [{'allocations': [
                {'resources': {'VCPU': 1, 'MEMORY_MB': 512, 'DISK_GB': 512},
                 'resource_provider': {'uuid': uuids.cn1}}
              ]
            }]
        alloc_reqs_by_rp_uuid = {
            uuids.cn1: allocs,
        }

        with mock.patch.object(self.driver.host_manager,
                               'get_filtered_hosts') as mock_get_hosts:
            mock_get_hosts.side_effect = fake_get_filtered_hosts
            hosts = self.driver._schedule(self.context, spec_obj,
                instance_uuids, alloc_reqs_by_rp_uuid,
                mock.sentinel.provider_summaries)

        self.assertEqual(len(hosts), 1)

        return spec_obj
Пример #10
0
    def buildup_nova_neutron_connection(self):

        self.context = get_admin_context()
        self.neutron = neutronapi.API()
        self.client = neutronapi.get_client(self.context)
Пример #11
0
 def __init__(self, fc_client, task_ops):
     super(NetworkOps, self).__init__(fc_client, task_ops)
     self._neutron = neutron_api.API()
     self.dvs_mapping = {}
     self.physnet_mapping = {}
     self._init_all_fc_dvs()