Exemplo n.º 1
0
    def test_init(self):
        ctxt = {
            "task": mock.MagicMock(),
            "config": {
                consts.SHARES_CONTEXT_NAME: {"foo": "bar"},
                "fake": {"fake_key": "fake_value"},
            },
        }

        inst = manila_shares.Shares(ctxt)

        self.assertEqual(
            {"foo": "bar", "shares_per_tenant": 1, "size": 1,
             "share_proto": "NFS", "share_type": None},
            inst.config)
        self.assertIn(
            rally_consts.JSON_SCHEMA, inst.CONFIG_SCHEMA.get("$schema"))
        self.assertFalse(inst.CONFIG_SCHEMA.get("additionalProperties"))
        self.assertEqual("object", inst.CONFIG_SCHEMA.get("type"))
        props = inst.CONFIG_SCHEMA.get("properties", {})
        self.assertEqual(
            {"minimum": 1, "type": "integer"}, props.get("shares_per_tenant"))
        self.assertEqual({"minimum": 1, "type": "integer"}, props.get("size"))
        self.assertEqual({"type": "string"}, props.get("share_proto"))
        self.assertEqual({"type": "string"}, props.get("share_type"))
        self.assertEqual(455, inst.get_order())
        self.assertEqual(consts.SHARES_CONTEXT_NAME, inst.get_name())
Exemplo n.º 2
0
    def test_setup(
            self,
            use_share_networks,
            mock_manila_scenario__create_share):
        share_type = "fake_share_type"
        ctxt = self._get_context(
            use_share_networks=use_share_networks, share_type=share_type)
        inst = manila_shares.Shares(ctxt)
        shares = [
            Fake(id="fake_share_id_%d" % s_id)
            for s_id in range(self.TENANTS_AMOUNT * self.SHARES_PER_TENANT)
        ]
        mock_manila_scenario__create_share.side_effect = shares
        expected_ctxt = copy.deepcopy(ctxt)

        inst.setup()

        self.assertEqual(
            self.TENANTS_AMOUNT * self.SHARES_PER_TENANT,
            mock_manila_scenario__create_share.call_count)
        for d in range(self.TENANTS_AMOUNT):
            self.assertEqual(
                [
                    s.to_dict() for s in shares[
                        (d * self.SHARES_PER_TENANT):(
                            d * self.SHARES_PER_TENANT + self.SHARES_PER_TENANT
                        )
                    ]
                ],
                inst.context.get("tenants", {}).get("%s" % d, {}).get("shares")
            )
        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"))
        if use_share_networks:
            mock_calls = [
                mock.call(
                    share_proto=ctxt["config"][consts.SHARES_CONTEXT_NAME][
                        "share_proto"],
                    size=ctxt["config"][consts.SHARES_CONTEXT_NAME]["size"],
                    share_type=ctxt["config"][consts.SHARES_CONTEXT_NAME][
                        "share_type"],
                    share_network=self.SHARE_NETWORKS[
                        int(t_id) % len(self.SHARE_NETWORKS)]["id"]
                ) for t_id in expected_ctxt["tenants"].keys()
            ]
        else:
            mock_calls = [
                mock.call(
                    share_proto=ctxt["config"][consts.SHARES_CONTEXT_NAME][
                        "share_proto"],
                    size=ctxt["config"][consts.SHARES_CONTEXT_NAME]["size"],
                    share_type=ctxt["config"][consts.SHARES_CONTEXT_NAME][
                        "share_type"],
                ) for t_id in expected_ctxt["tenants"].keys()
            ]
        mock_manila_scenario__create_share.assert_has_calls(
            mock_calls, any_order=True)
Exemplo n.º 3
0
    def test_cleanup(self, mock_cleanup_manager_cleanup,
                     mock_manila_scenario__create_share):
        ctxt = self._get_context()
        inst = manila_shares.Shares(ctxt)
        shares = [
            Fake(id="fake_share_id_%d" % s_id)
            for s_id in range(self.TENANTS_AMOUNT * self.SHARES_PER_TENANT)
        ]
        mock_manila_scenario__create_share.side_effect = shares
        inst.setup()

        inst.cleanup()

        mock_cleanup_manager_cleanup.assert_called_once_with(
            names=["manila.shares"],
            users=inst.context.get("users", []),
        )