Beispiel #1
0
    def test_add_event_k8s_exception(self):
        self.client.post = mock.MagicMock()
        self.client.post.side_effect = exc.K8sClientException
        pod = fake.get_k8s_pod()

        self.assertDictEqual(self.client.add_event(pod, 'reason1', 'message2'),
                             {})
Beispiel #2
0
    def test_add_event(self):
        self.client.post = mock.MagicMock()
        get_hex_ts = self.client._get_hex_timestamp = mock.MagicMock()
        get_hex_ts.return_value = 'deadc0de'

        namespace = 'n1'
        uid = 'deadbeef'
        name = 'pod-123'
        pod = fake.get_k8s_pod(name=name, namespace=namespace, uid=uid)
        event_name = f'{name}.deadc0de'

        self.client.add_event(pod, 'reason', 'message')

        # Event path
        url = self.client.post.call_args[0][0]
        data = self.client.post.call_args[0][1]
        self.assertEqual(url, f'/api/v1/namespaces/{namespace}/events')

        # Event fields
        self.assertEqual(data['metadata']['name'], event_name)
        self.assertEqual(data['reason'], 'reason')
        self.assertEqual(data['message'], 'message')
        self.assertEqual(data['type'], 'Normal')

        # involvedObject
        self.assertDictEqual(
            data['involvedObject'], {
                'apiVersion': pod['apiVersion'],
                'kind': pod['kind'],
                'name': name,
                'namespace': namespace,
                'uid': uid
            })
    def test_neutron_to_osvif_nested_dpdk(self, m_mk_port_profile, m_mk_vif,
                                          m_make_vif_network, m_is_port_active,
                                          m_get_vif_name):
        vif_plugin = const.K8S_OS_VIF_NOOP_PLUGIN
        port_id = mock.sentinel.port_id
        mac_address = mock.sentinel.mac_address
        port_filter = mock.sentinel.port_filter
        subnets = mock.sentinel.subnets
        network = mock.sentinel.network
        port_active = mock.sentinel.port_active
        vif_name = mock.sentinel.vif_name
        vif = mock.sentinel.vif
        port_profile = mock.sentinel.port_profile

        m_make_vif_network.return_value = network
        m_is_port_active.return_value = port_active
        m_get_vif_name.return_value = vif_name
        m_mk_vif.return_value = vif
        m_mk_port_profile.return_value = port_profile

        pod = fake.get_k8s_pod()

        port = {
            'id': port_id,
            'mac_address': mac_address,
            'binding:vif_details': {
                'port_filter': port_filter
            },
        }

        self.assertEqual(vif,
                         ovu.neutron_to_osvif_vif_dpdk(port, subnets, pod))

        m_make_vif_network.assert_called_once_with(port, subnets)
        m_is_port_active.assert_called_once_with(port)
        m_get_vif_name.assert_called_once_with(port)
        m_mk_port_profile.assert_called_once_with(
            l3_setup=False, selflink=utils.get_res_link(pod))

        m_mk_vif.assert_called_once_with(id=port_id,
                                         port_profile=port_profile,
                                         address=mac_address,
                                         network=network,
                                         has_traffic_filtering=port_filter,
                                         preserve_on_delete=False,
                                         active=port_active,
                                         plugin=vif_plugin,
                                         pci_address="",
                                         dev_driver="",
                                         vif_name=vif_name)
    def setUp(self):
        super(TestSriovVIFDriver, self).setUp()

        self._res_map = {
            SRIOV_PHYSNET_A: SRIOV_RESOURCE_NAME_A,
            SRIOV_PHYSNET_B: SRIOV_RESOURCE_NAME_B
        }
        sriov_request = {
            drvs.sriov_make_resource(k_const.K8S_SRIOV_PREFIX, SRIOV_RESOURCE_NAME_A):
            (str(AMOUNT_FOR_SUBNET_A)),
            drvs.sriov_make_resource(k_const.K8S_SRIOV_PREFIX, SRIOV_RESOURCE_NAME_B):
            (str(AMOUNT_FOR_SUBNET_B))
        }
        self._pod = fake.get_k8s_pod()
        self._pod['status'] = {'phase': k_const.K8S_POD_STATUS_PENDING}
        self._pod['spec'] = {
            'hostNetwork': False,
            'nodeName': 'hostname',
            'containers': [{
                'resources': {
                    'requests': sriov_request
                }
            }]
        }
Beispiel #5
0
    def setUp(self):
        super(TestVIFHandler, self).setUp()

        self._project_id = mock.sentinel.project_id
        self._subnets = mock.sentinel.subnets
        self._security_groups = mock.sentinel.security_groups
        self._vif = os_obj.vif.VIFBase()
        self._vif.active = True
        self._vif_serialized = mock.sentinel.vif_serialized
        self._multi_vif_drv = mock.MagicMock(spec=drivers.MultiVIFDriver)
        self._additioan_vifs = []
        self._state = vif.PodState(default_vif=self._vif)

        self._pod_version = mock.sentinel.pod_version
        self._pod_link = mock.sentinel.pod_link
        self._pod_namespace = 'namespace1'
        self._pod_uid = mock.sentinel.pod_uid
        self._pod_name = 'pod1'
        self._pod = fake.get_k8s_pod()
        self._pod['status'] = {'phase': k_const.K8S_POD_STATUS_PENDING}
        self._pod['spec'] = {'hostNetwork': False, 'nodeName': 'hostname'}

        self._kp_version = mock.sentinel.kp_version
        self._kp_link = mock.sentinel.kp_link
        self._kp = {
            'apiVersion': 'openstack.org/v1',
            'kind': 'KuryrPort',
            'metadata': {
                'resourceVersion': self._kp_version,
                'selfLink': mock.sentinel.kp_link,
                'namespace': self._pod_namespace,
                'labels': mock.ANY
            },
            'spec': {
                'podUid': self._pod_uid,
                'podNodeName': 'hostname'
            },
            'status': {
                'vifs': {}
            }
        }

        self._handler = mock.MagicMock(spec=h_vif.VIFHandler)
        self._handler._drv_project = mock.Mock(spec=drivers.PodProjectDriver)
        self._handler._drv_subnets = mock.Mock(spec=drivers.PodSubnetsDriver)
        self._handler._drv_sg = mock.Mock(spec=drivers.PodSecurityGroupsDriver)
        self._handler._drv_vif = mock.Mock(spec=drivers.PodVIFDriver)
        self._handler._drv_vif_pool = mock.MagicMock(
            spec=drivers.VIFPoolDriver)
        self._handler._drv_multi_vif = [self._multi_vif_drv]
        self._handler.k8s = mock.Mock()

        self._get_project = self._handler._drv_project.get_project
        self._get_subnets = self._handler._drv_subnets.get_subnets
        self._get_security_groups = self._handler._drv_sg.get_security_groups
        self._set_vifs_driver = self._handler._drv_vif_pool.set_vif_driver
        self._request_vif = self._handler._drv_vif_pool.request_vif
        self._release_vif = self._handler._drv_vif_pool.release_vif
        self._activate_vif = self._handler._drv_vif_pool.activate_vif
        self._is_pod_scheduled = self._handler._is_pod_scheduled
        self._request_additional_vifs = \
            self._multi_vif_drv.request_additional_vifs

        self._request_vif.return_value = self._vif
        self._request_additional_vifs.return_value = self._additioan_vifs
        self._is_pod_scheduled.return_value = True
        self._get_project.return_value = self._project_id
        self._get_subnets.return_value = self._subnets
        self._get_security_groups.return_value = self._security_groups
        self._set_vifs_driver.return_value = mock.Mock(
            spec=drivers.PodVIFDriver)