コード例 #1
0
    def setUp(self):
        InstanceIpSM._cassandra = mock.MagicMock()
        InstanceIpSM._cassandra.read = test_utils.iip_db_read
        VirtualMachineInterfaceSM._cassandra = mock.MagicMock()
        VirtualMachineInterfaceSM._cassandra.read = test_utils.vmi_db_read
        VirtualMachineSM._cassandra = mock.MagicMock()
        VirtualMachineSM._cassandra.read = test_utils.vm_db_read
        VirtualRouterSM._cassandra = mock.MagicMock()
        VirtualRouterSM._cassandra.read = test_utils.vr_db_read
        VirtualNetworkSM._cassandra = mock.MagicMock()
        VirtualNetworkSM._cassandra.read = test_utils.vn_db_read

        self.mocked_vnc = mock.MagicMock()
        self.mocked_vnc.fq_name_to_id = test_utils.get_vn_id_for_fq_name
        self.mocked_vnc.virtual_machine_interface_create = test_utils.vmi_create
        self.mocked_vnc.virtual_network_create = test_utils.vn_create
        self.mocked_vnc.instance_ip_create = test_utils.iip_create

        self.nova_mock = mock.MagicMock()
        self.mocked_db = mock.MagicMock()

        self.mocked_args = mock.MagicMock()
        self.mocked_args.availability_zone = None

        self.mocked_manager = mock.MagicMock()

        self.netns_manager = NetworkNamespaceManager(
            db=self.mocked_db,
            logger=mock.MagicMock(),
            vnc_lib=self.mocked_vnc,
            vrouter_scheduler=mock.MagicMock(),
            nova_client=self.nova_mock,
            agent_manager=self.mocked_manager,
            args=self.mocked_args)
コード例 #2
0
    def setUp(self):
        def get_vn_id(obj_type, fq_name):
            if obj_type != 'virtual-network':
                return
            for vn in VirtualNetworkSM.values():
                if vn.fq_name == fq_name:
                    return vn.uuid
            raise NoIdError(fq_name)

        def vmi_create(vmi_obj):
            vmi_obj.uuid = 'fake-vmi-uuid'
            return

        def vn_create(vn_obj):
            vn_obj.uuid = 'fake-vn-uuid'
            return

        def vn_read(vn_id):
            vn_obj = {}
            vn_obj['uuid'] = 'fake-vn-uuid'
            vn_obj['fq_name'] = ['fake-domain', 'fake-project', 'fake-vn-uuid']
            return True, [vn_obj]

        def vm_read(vm_id):
            class SI(object):
                def __init__(self, name, fq_name):
                    self.name = name
                    self.fq_name = fq_name

            vm_obj = {}
            vm_obj['uuid'] = 'fake-vm-uuid'
            vm_obj['fq_name'] = ['fake-vm-uuid']
            fq_name = ['fake-domain', 'fake-project', 'fake-snat-instance']
            name = 'fake-snat-instance'
            si = SI(name, fq_name)
            instance_name = self.netns_manager._get_instance_name(si, 0)
            vm_obj['display_name'] = instance_name + '__' + 'network-namespace'
            return True, [vm_obj]

        def vr_read(vm_id):
            vr_obj = {}
            vr_obj['uuid'] = 'fake-vr-uuid'
            vr_obj['fq_name'] = ['fake-vr-uuid']
            return True, [vr_obj]

        VirtualMachineSM._cassandra = mock.MagicMock()
        VirtualMachineSM._cassandra._cassandra_virtual_machine_read = vm_read

        VirtualRouterSM._cassandra = mock.MagicMock()
        VirtualRouterSM._cassandra._cassandra_virtual_router_read = vr_read

        VirtualNetworkSM._cassandra = mock.MagicMock()
        VirtualNetworkSM._cassandra._cassandra_virtual_network_read = vn_read

        self.mocked_vnc = mock.MagicMock()
        self.mocked_vnc.fq_name_to_id = get_vn_id
        self.mocked_vnc.virtual_machine_interface_create = vmi_create
        self.mocked_vnc.virtual_network_create = vn_create

        self.nova_mock = mock.MagicMock()
        self.mocked_db = mock.MagicMock()

        self.mocked_args = mock.MagicMock()
        self.mocked_args.availability_zone = None

        self.netns_manager = NetworkNamespaceManager(
            db=self.mocked_db,
            logger=mock.MagicMock(),
            vnc_lib=self.mocked_vnc,
            vrouter_scheduler=mock.MagicMock(),
            nova_client=self.nova_mock,
            args=self.mocked_args)