Ejemplo n.º 1
0
    def test_update_quota_not_in_sizes_asc(self):
        """
        Tests that the quota will still update to a size even if it is not
        placed in QUOTA_SIZES_ASC
        """

        project = mock.Mock()
        project.id = "test_project_id"
        project.name = "test_project"
        project.domain = "default"
        project.roles = {}

        user = mock.Mock()
        user.id = "user_id"
        user.name = "*****@*****.**"
        user.email = "*****@*****.**"
        user.domain = "default"
        user.password = "******"

        setup_identity_cache(projects=[project], users=[user])
        setup_mock_caches("RegionOne", project.id)
        setup_mock_caches("RegionTwo", project.id)

        task = Task.objects.create(keystone_user={"roles": ["admin"]})

        data = {
            "project_id": "test_project_id",
            "size": "large",
            "domain_id": "default",
            "regions": ["RegionOne", "RegionTwo"],
        }

        action = UpdateProjectQuotasAction(data, task=task, order=1)

        action.prepare()
        self.assertEqual(action.valid, True)

        action.approve()
        self.assertEqual(action.valid, True)

        # check the quotas were updated
        cinderquota = cinder_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(cinderquota["gigabytes"], 50000)
        novaquota = nova_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(novaquota["ram"], 655360)
        neutronquota = neutron_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(neutronquota["network"], 10)

        cinderquota = cinder_cache["RegionTwo"]["test_project_id"]["quota"]
        self.assertEqual(cinderquota["gigabytes"], 50000)
        novaquota = nova_cache["RegionTwo"]["test_project_id"]["quota"]
        self.assertEqual(novaquota["ram"], 655360)
        neutronquota = neutron_cache["RegionTwo"]["test_project_id"]["quota"]
        self.assertEqual(neutronquota["network"], 10)
Ejemplo n.º 2
0
    def test_update_quota_multi_region(self):
        """
        Sets a new quota on all services of a project in multiple regions
        """
        project = mock.Mock()
        project.id = "test_project_id"
        project.name = "test_project"
        project.domain = "default"
        project.roles = {}

        user = mock.Mock()
        user.id = "user_id"
        user.name = "*****@*****.**"
        user.email = "*****@*****.**"
        user.domain = "default"
        user.password = "******"

        setup_identity_cache(projects=[project], users=[user])
        setup_mock_caches("RegionOne", project.id)
        setup_mock_caches("RegionTwo", project.id)

        task = Task.objects.create(keystone_user={"roles": ["admin"]})

        data = {
            "project_id": "test_project_id",
            "size": "large",
            "domain_id": "default",
            "regions": ["RegionOne", "RegionTwo"],
            "user_id": "user_id",
        }

        action = UpdateProjectQuotasAction(data, task=task, order=1)

        action.prepare()
        self.assertEqual(action.valid, True)

        action.approve()
        self.assertEqual(action.valid, True)

        # check the quotas were updated
        cinderquota = cinder_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(cinderquota["gigabytes"], 50000)
        novaquota = nova_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(novaquota["ram"], 655360)
        neutronquota = neutron_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(neutronquota["network"], 10)

        cinderquota = cinder_cache["RegionTwo"]["test_project_id"]["quota"]
        self.assertEqual(cinderquota["gigabytes"], 50000)
        novaquota = nova_cache["RegionTwo"]["test_project_id"]["quota"]
        self.assertEqual(novaquota["ram"], 655360)
        neutronquota = neutron_cache["RegionTwo"]["test_project_id"]["quota"]
        self.assertEqual(neutronquota["network"], 10)
Ejemplo n.º 3
0
    def test_update_quota_extra_services(self):
        """Tests the quota update of extra services over and above
        core openstack services.
        """
        project = mock.Mock()
        project.id = "test_project_id"
        project.name = "test_project"
        project.domain = "default"
        project.roles = {}

        user = mock.Mock()
        user.id = "user_id"
        user.name = "*****@*****.**"
        user.email = "*****@*****.**"
        user.domain = "default"
        user.password = "******"

        setup_identity_cache(projects=[project], users=[user])
        setup_mock_caches("RegionOne", project.id)

        task = Task.objects.create(keystone_user={"roles": ["admin"]})

        data = {
            "project_id": "test_project_id",
            "size": "large",
            "domain_id": "default",
            "regions": ["RegionOne"],
        }

        action = UpdateProjectQuotasAction(data, task=task, order=1)

        action.prepare()
        self.assertEqual(action.valid, True)

        action.approve()
        self.assertEqual(action.valid, True)

        # check the quotas were updated
        cinderquota = cinder_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(cinderquota["gigabytes"], 50000)
        novaquota = nova_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(novaquota["ram"], 655360)
        neutronquota = neutron_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(neutronquota["network"], 10)
        octaviaquota = octavia_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(octaviaquota["load_balancer"], 10)
        trove_quota = trove_cache["RegionOne"]["test_project_id"]["quota"]
        self.assertEqual(trove_quota["instances"], 20)
Ejemplo n.º 4
0
    def test_quota_downgrade_fails_when_usage_exceeds_requested_quota(self):
        """Ensures that a quota change will fail validation when the
        current usage exceeds the requested quota.
        """
        project = mock.Mock()
        project.id = "test_project_id"
        project.name = "test_project"
        project.domain = "default"
        project.roles = {}

        user = mock.Mock()
        user.id = "user_id"
        user.name = "*****@*****.**"
        user.email = "*****@*****.**"
        user.domain = "default"
        user.password = "******"

        setup_identity_cache(projects=[project], users=[user])
        setup_mock_caches("RegionOne", project.id)

        task = Task.objects.create(keystone_user={"roles": ["admin"]})

        data = {
            "project_id": "test_project_id",
            "size": "small",
            "domain_id": "default",
            "regions": ["RegionOne"],
        }

        # setup 2 load balancers
        octavia_cache["RegionOne"][project.id]["load_balancer"] = [
            {
                "id": "fake_id"
            },
            {
                "id": "fake_id2"
            },
        ]

        trove_cache["RegionOne"][project.id]["instances"] = [
            {
                "id": "fake_id"
            },
            {
                "id": "fake_id2"
            },
            {
                "id": "fake_id3"
            },
            {
                "id": "fake_id4"
            },
        ]

        action = UpdateProjectQuotasAction(data, task=task, order=1)

        action.prepare()
        self.assertEqual(action.valid, False)

        action.approve()
        self.assertEqual(action.valid, False)

        # check the quotas were updated
        octaviaquota = octavia_cache["RegionOne"]["test_project_id"]["quota"]
        trove_quota = trove_cache["RegionOne"]["test_project_id"]["quota"]

        # Still set to default
        self.assertEqual(octaviaquota["load_balancer"], 1)
        self.assertEqual(trove_quota["instances"], 3)