Beispiel #1
0
    def test_setup_autocreate_share_networks_wo_security_services(
            self, neutron,
            mock_manila_scenario__add_security_service_to_share_network,
            mock_manila_scenario__create_share_network, mock_clients):
        networks_per_tenant = 2
        ctxt = self._get_context(
            networks_per_tenant=networks_per_tenant,
            neutron_network_provider=neutron,
        )
        inst = manila_share_networks.ShareNetworks(ctxt)

        inst.setup()

        self.assertEqual(ctxt["task"], inst.context.get("task"))
        self.assertEqual(ctxt["config"], inst.context.get("config"))
        self.assertEqual(ctxt["users"], inst.context.get("users"))
        self.assertEqual(ctxt["tenants"], inst.context.get("tenants"))
        self.assertFalse(
            mock_manila_scenario__add_security_service_to_share_network.called)
        if neutron:
            sn_args = {
                "neutron_net_id": mock.ANY,
                "neutron_subnet_id": mock.ANY,
            }
        else:
            sn_args = {"nova_net_id": mock.ANY}
        expected_calls = [mock.call(**sn_args), mock.call().to_dict()]
        mock_manila_scenario__create_share_network.assert_has_calls(
            expected_calls * (self.TENANTS_AMOUNT * networks_per_tenant))
        mock_clients.assert_has_calls([
            mock.call(MOCK_USER_CREDENTIAL) for i in range(self.TENANTS_AMOUNT)
        ])
Beispiel #2
0
    def test_setup_use_existing_share_networks_with_empty_list(self):
        ctxt = copy.deepcopy(self.ctxt_use_existing)
        ctxt["config"][
            consts.SHARE_NETWORKS_CONTEXT_NAME]["share_networks"] = {}
        inst = manila_share_networks.ShareNetworks(ctxt)

        self.assertRaises(exceptions.ContextSetupFailure, inst.setup)
Beispiel #3
0
    def test_setup_use_existing_share_networks_sn_not_found(
            self, mock_manila_scenario__list_share_networks, mock_clients):
        ctxt = copy.deepcopy(self.ctxt_use_existing)
        ctxt["config"][
            consts.SHARE_NETWORKS_CONTEXT_NAME]["share_networks"] = {
                "tenant_1_id": ["foo"]
            }
        inst = manila_share_networks.ShareNetworks(ctxt)
        mock_manila_scenario__list_share_networks.return_value = (
            self.existing_sns)

        self.assertRaises(exceptions.ContextSetupFailure, inst.setup)
Beispiel #4
0
    def test_setup_autocreate_share_networks_with_security_services(
            self, neutron,
            mock_manila_scenario__add_security_service_to_share_network,
            mock_manila_scenario__create_share_network, mock_clients):
        networks_per_tenant = 2
        ctxt = self._get_context(
            networks_per_tenant=networks_per_tenant,
            neutron_network_provider=neutron,
            use_security_services=True,
        )
        inst = manila_share_networks.ShareNetworks(ctxt)
        for tenant_id in list(ctxt["tenants"].keys()):
            inst.context["tenants"][tenant_id][
                consts.SECURITY_SERVICES_CONTEXT_NAME] = {
                    "security_services":
                    [Fake(id="fake_id").to_dict() for i in (1, 2, 3)]
                }

        inst.setup()

        self.assertEqual(ctxt["task"], inst.context.get("task"))
        self.assertEqual(ctxt["config"], inst.context.get("config"))
        self.assertEqual(ctxt["users"], inst.context.get("users"))
        self.assertEqual(ctxt["tenants"], inst.context.get("tenants"))
        mock_add_security_service_to_share_network = (
            mock_manila_scenario__add_security_service_to_share_network)
        mock_add_security_service_to_share_network.assert_has_calls([
            mock.call(mock.ANY, mock.ANY)
            for _ in range(self.TENANTS_AMOUNT * networks_per_tenant *
                           len(self.SECURITY_SERVICES))
        ])
        if neutron:
            sn_args = {
                "neutron_net_id": mock.ANY,
                "neutron_subnet_id": mock.ANY,
            }
        else:
            sn_args = {"nova_net_id": mock.ANY}
        expected_calls = [
            mock.call(**sn_args),
            mock.call().to_dict(),
            mock.ANY,
            mock.ANY,
            mock.ANY,
        ]
        mock_manila_scenario__create_share_network.assert_has_calls(
            expected_calls * (self.TENANTS_AMOUNT * networks_per_tenant))
        mock_clients.assert_has_calls([
            mock.call(MOCK_USER_CREDENTIAL) for i in range(self.TENANTS_AMOUNT)
        ])
Beispiel #5
0
    def test_cleanup_used_existing_share_networks(
            self, mock_manila_scenario__list_share_networks,
            mock_manila_scenario__list_share_servers,
            mock_manila_scenario__delete_share_network, mock_clients):
        inst = manila_share_networks.ShareNetworks(self.ctxt_use_existing)
        mock_manila_scenario__list_share_networks.return_value = (
            self.existing_sns)
        inst.setup()

        inst.cleanup()

        self.assertFalse(mock_manila_scenario__list_share_servers.called)
        self.assertFalse(mock_manila_scenario__delete_share_network.called)
        self.assertEqual(2, mock_clients.call_count)
        for user in self.ctxt_use_existing["users"]:
            self.assertIn(mock.call(user["credential"]),
                          mock_clients.mock_calls)
Beispiel #6
0
    def test_setup_share_networks_disabled(self):
        ctxt = {
            "task": mock.MagicMock(),
            "config": {
                consts.SHARE_NETWORKS_CONTEXT_NAME: {
                    "use_share_networks": False,
                },
            },
            consts.SHARE_NETWORKS_CONTEXT_NAME: {},
        }
        inst = manila_share_networks.ShareNetworks(ctxt)

        expected_ctxt = copy.deepcopy(inst.context)

        inst.setup()

        self.assertEqual(expected_ctxt, inst.context)
Beispiel #7
0
    def test_setup_autocreate_share_networks_wo_networks(
            self, mock_manila_scenario__add_security_service_to_share_network,
            mock_manila_scenario__create_share_network, mock_clients):
        ctxt = self._get_context(networks_per_tenant=0)
        inst = manila_share_networks.ShareNetworks(ctxt)

        inst.setup()

        self.assertEqual(ctxt["task"], inst.context.get("task"))
        self.assertEqual(ctxt["config"], inst.context.get("config"))
        self.assertEqual(ctxt["users"], inst.context.get("users"))
        self.assertEqual(ctxt["tenants"], inst.context.get("tenants"))
        self.assertFalse(
            mock_manila_scenario__add_security_service_to_share_network.called)
        expected_calls = [mock.call(), mock.call().to_dict()]
        mock_manila_scenario__create_share_network.assert_has_calls(
            expected_calls * self.TENANTS_AMOUNT)
        mock_clients.assert_has_calls([
            mock.call(MOCK_USER_CREDENTIAL) for i in range(self.TENANTS_AMOUNT)
        ])
Beispiel #8
0
    def test_init(self):
        context = {
            "task": mock.MagicMock(),
            "config": {
                consts.SHARE_NETWORKS_CONTEXT_NAME: {
                    "foo": "bar"
                },
                "not_manila": {
                    "not_manila_key": "not_manila_value"
                },
            },
        }

        inst = manila_share_networks.ShareNetworks(context)

        self.assertEqual(
            {
                "foo": "bar",
                "share_networks": {},
                "use_share_networks": False
            }, inst.config)
Beispiel #9
0
    def test_setup_use_existing_share_networks(
            self, mock_manila_scenario__list_share_networks, mock_clients):
        existing_sns = self.existing_sns
        expected_ctxt = copy.deepcopy(self.ctxt_use_existing)
        inst = manila_share_networks.ShareNetworks(self.ctxt_use_existing)
        mock_manila_scenario__list_share_networks.return_value = (
            self.existing_sns)
        expected_ctxt.update({
            "delete_share_networks": False,
            "tenants": {
                "tenant_1_id": {
                    "id": "tenant_1_id",
                    "name": "tenant_1_name",
                    consts.SHARE_NETWORKS_CONTEXT_NAME: {
                        "share_networks":
                        [sn.to_dict() for sn in existing_sns[0:2]],
                    },
                },
                "tenant_2_id": {
                    "id": "tenant_2_id",
                    "name": "tenant_2_name",
                    consts.SHARE_NETWORKS_CONTEXT_NAME: {
                        "share_networks":
                        [sn.to_dict() for sn in existing_sns[2:5]],
                    },
                },
            }
        })

        inst.setup()

        self.assertEqual(expected_ctxt["task"], inst.context.get("task"))
        self.assertEqual(expected_ctxt["config"], inst.context.get("config"))
        self.assertEqual(expected_ctxt["users"], inst.context.get("users"))
        self.assertFalse(
            inst.context.get(consts.SHARE_NETWORKS_CONTEXT_NAME,
                             {}).get("delete_share_networks"))
        self.assertEqual(expected_ctxt["tenants"], inst.context.get("tenants"))
Beispiel #10
0
    def test_cleanup_autocreated_share_networks(self, mock_cleanup):
        task_id = "task"
        ctxt = {
            "config": {
                "manila_share_networks": {
                    "use_share_networks": True
                }
            },
            "users": [mock.Mock()],
            "task": {
                "uuid": task_id
            }
        }

        inst = manila_share_networks.ShareNetworks(ctxt)

        inst.cleanup()

        mock_cleanup.assert_called_once_with(
            names=["manila.share_networks"],
            users=ctxt["users"],
            superclass=manila_share_networks.ShareNetworks,
            task_id=task_id)
Beispiel #11
0
    def test_setup_use_existing_share_networks_tenant_not_found(self):
        ctxt = copy.deepcopy(self.ctxt_use_existing)
        ctxt.update({"tenants": {}})
        inst = manila_share_networks.ShareNetworks(ctxt)

        self.assertRaises(exceptions.ContextSetupFailure, inst.setup)