Beispiel #1
0
class KubernetesPolicyDriverTest(unittest.TestCase):
    """
    Test class for DefaultDenyInboundDriver class.
    """
    def setUp(self):
        self.network_name = "net-name"
        self.namespace = "default"
        self.driver = KubernetesPolicyDriver(self.network_name, self.namespace,
                                             None, None, None, None, None,
                                             None)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client

    def test_apply_profile(self):
        endpoint = MagicMock(spec=Endpoint)
        endpoint.endpoint_id = "12345"

        # Mock out the k8s API call.
        self.driver._get_api_pod = Mock(spec=self.driver._get_api_pod)
        self.driver._get_api_pod.return_value = \
            {"metadata": {"labels": {"label1": "labelval"}}}

        # Call
        self.driver.apply_profile(endpoint)

        # Assert
        self.client.update_endpoint.assert_called_once_with(endpoint)

    def test_remove_profile(self):
        """
        Should do nothing.
        """
        self.driver.remove_profile()
class KubernetesPolicyDriverTest(unittest.TestCase):
    """
    Test class for DefaultDenyInboundDriver class.
    """
    def setUp(self):
        self.network_name = "net-name"
        self.namespace = "default"
        self.driver = KubernetesPolicyDriver(self.network_name, self.namespace,
                                             None, None, None, None, None, None)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client

    def test_apply_profile(self):
        endpoint = MagicMock(spec=Endpoint)
        endpoint.endpoint_id = "12345"

        # Mock out the k8s API call.
        self.driver._get_api_pod = Mock(spec=self.driver._get_api_pod)
        self.driver._get_api_pod.return_value = \
            {"metadata": {"labels": {"label1": "labelval"}}}

        # Call
        self.driver.apply_profile(endpoint)

        # Assert
        self.client.update_endpoint.assert_called_once_with(endpoint)


    def test_remove_profile(self):
        """
        Should do nothing.
        """
        self.driver.remove_profile()
Beispiel #3
0
    def setUp(self):
        self.network_name = "net-name"
        self.namespace = "default"
        self.driver = KubernetesPolicyDriver(self.network_name, self.namespace,
                                             None, None, None, None, None,
                                             None)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client
    def setUp(self):
        self.network_name = "net-name"
        self.namespace = "default"
        self.driver = KubernetesPolicyDriver(self.network_name, self.namespace,
                                             None, None, None, None, None, None)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client