Exemplo n.º 1
0
    def create_plugin(self):
        self.network_config = {
            "name": self.network_name,
            "type": self.plugin_type,
            "ipam": {
                "type": self.ipam_type,
            }
        }

        self.env = {
            CNI_COMMAND_ENV: self.command,
            CNI_CONTAINERID_ENV: self.container_id,
            CNI_IFNAME_ENV: self.cni_ifname,
            CNI_ARGS_ENV: self.cni_args,
            CNI_PATH_ENV: self.cni_path,
            CNI_NETNS_ENV: self.cni_netns
        }

        # Create the CniPlugin to test.
        plugin = CniPlugin(self.network_config, self.env)

        # Mock out the datastore client.
        plugin._client = self.client
        plugin.policy_driver._client = self.client

        return plugin
Exemplo n.º 2
0
    def setUp(self):
        """
        Per-test setup method.
        """
        self.container_id = "ff3afbd1-17ad-499d-b514-72438c009e81"
        self.network_config = {
            "name": "ut-network",
            "type": "calico",
            "ipam": {
                "type": "calico-ipam",
                "subnet": "10.22.0.0/16",
                "routes": [{
                    "dst": "0.0.0.0/0"
                }],
                "range-start": "",
                "range-end": ""
            }
        }
        self.env = {
            CNI_CONTAINERID_ENV: self.container_id,
            CNI_IFNAME_ENV: "eth0",
            CNI_ARGS_ENV: "",
            CNI_COMMAND_ENV: CNI_CMD_ADD,
            CNI_PATH_ENV: "/usr/bin/rkt/",
            CNI_NETNS_ENV: "netns",
        }

        # Create the CniPlugin to test.
        self.plugin = CniPlugin(self.network_config, self.env)

        # Mock out policy driver.
        self.plugin.policy_driver = MagicMock(spec=DefaultPolicyDriver)

        # Mock out the datastore client.
        self.m_datastore_client = MagicMock(spec=DatastoreClient)
        self.plugin._client = self.m_datastore_client