Esempio n. 1
0
    def test_get(self):
        sess = mock.Mock(spec=adapter.Adapter)
        resp = mock.Mock()
        sess.get.return_value = resp
        resp.json.return_value = copy.deepcopy(LIMITS_BODY)
        resp.headers = {}
        resp.status_code = 200

        sot = limits.Limits().get(sess)

        self.assertEqual(ABSOLUTE_LIMITS["maxImageMeta"],
                         sot.absolute.image_meta)
        self.assertEqual(ABSOLUTE_LIMITS["maxPersonality"],
                         sot.absolute.personality)
        self.assertEqual(ABSOLUTE_LIMITS["maxPersonalitySize"],
                         sot.absolute.personality_size)
        self.assertEqual(ABSOLUTE_LIMITS["maxSecurityGroupRules"],
                         sot.absolute.security_group_rules)
        self.assertEqual(ABSOLUTE_LIMITS["maxSecurityGroups"],
                         sot.absolute.security_groups)
        self.assertEqual(ABSOLUTE_LIMITS["maxServerMeta"],
                         sot.absolute.server_meta)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalCores"],
                         sot.absolute.total_cores)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalFloatingIps"],
                         sot.absolute.floating_ips)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalInstances"],
                         sot.absolute.instances)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalKeypairs"],
                         sot.absolute.keypairs)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalRAMSize"],
                         sot.absolute.total_ram)
        self.assertEqual(ABSOLUTE_LIMITS["maxServerGroups"],
                         sot.absolute.server_groups)
        self.assertEqual(ABSOLUTE_LIMITS["maxServerGroupMembers"],
                         sot.absolute.server_group_members)
        self.assertEqual(ABSOLUTE_LIMITS["totalFloatingIpsUsed"],
                         sot.absolute.floating_ips_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalSecurityGroupsUsed"],
                         sot.absolute.security_groups_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalRAMUsed"],
                         sot.absolute.total_ram_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalInstancesUsed"],
                         sot.absolute.instances_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalServerGroupsUsed"],
                         sot.absolute.server_groups_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalCoresUsed"],
                         sot.absolute.total_cores_used)

        self.assertEqual(RATE_LIMIT["uri"], sot.rate[0].uri)
        self.assertEqual(RATE_LIMIT["regex"], sot.rate[0].regex)
        self.assertEqual(RATE_LIMIT["limit"], sot.rate[0].limits)

        dsot = sot.to_dict()

        self.assertIsInstance(dsot['rate'][0], dict)
        self.assertIsInstance(dsot['absolute'], dict)
        self.assertEqual(RATE_LIMIT["uri"], dsot['rate'][0]['uri'])
        self.assertEqual(ABSOLUTE_LIMITS["totalSecurityGroupsUsed"],
                         dsot['absolute']['security_groups_used'])
Esempio n. 2
0
 def test_basic(self):
     sot = limits.Limits()
     self.assertEqual("limits", sot.resource_key)
     self.assertEqual("/limits", sot.base_path)
     self.assertTrue(sot.allow_fetch)
     self.assertFalse(sot.allow_create)
     self.assertFalse(sot.allow_commit)
     self.assertFalse(sot.allow_delete)
     self.assertFalse(sot.allow_list)
Esempio n. 3
0
    def limits(self):
        """Retrieve limits that are applied to the project's account

        :returns: A Limits object, including both
                  :class:`~openstack.compute.v2.limits.AbsoluteLimits` and
                  :class:`~openstack.compute.v2.limits.RateLimits`
        :rtype: :class:`~openstack.compute.v2.limits.Limits`
        """
        return limits.Limits().get(self.session)
    def test_get(self, mock_get):
        # Only return values under the limits key since that's our
        # resource_key, which would be filtered out in get_data_by_id.
        mock_get.return_value = LIMITS_BODY["limits"]

        sot = limits.Limits().get("fake session")

        self.assertEqual(sot.absolute, limits.AbsoluteLimits(ABSOLUTE_LIMITS))
        self.assertEqual(sot.rate, [limits.RateLimits(RATE_LIMIT)])
Esempio n. 5
0
 def test_basic(self):
     sot = limits.Limits()
     self.assertEqual("limits", sot.resource_key)
     self.assertEqual("/limits", sot.base_path)
     self.assertEqual("compute", sot.service.service_type)
     self.assertTrue(sot.allow_get)
     self.assertFalse(sot.allow_create)
     self.assertFalse(sot.allow_update)
     self.assertFalse(sot.allow_delete)
     self.assertFalse(sot.allow_list)
Esempio n. 6
0
    def test_get(self):
        sess = mock.Mock()
        resp = mock.Mock()
        sess.get.return_value = resp
        resp.json.return_value = LIMITS_BODY

        sot = limits.Limits().get(sess)

        self.assertEqual(ABSOLUTE_LIMITS["maxImageMeta"],
                         sot.absolute.image_meta)
        self.assertEqual(ABSOLUTE_LIMITS["maxPersonality"],
                         sot.absolute.personality)
        self.assertEqual(ABSOLUTE_LIMITS["maxPersonalitySize"],
                         sot.absolute.personality_size)
        self.assertEqual(ABSOLUTE_LIMITS["maxSecurityGroupRules"],
                         sot.absolute.security_group_rules)
        self.assertEqual(ABSOLUTE_LIMITS["maxSecurityGroups"],
                         sot.absolute.security_groups)
        self.assertEqual(ABSOLUTE_LIMITS["maxServerMeta"],
                         sot.absolute.server_meta)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalCores"],
                         sot.absolute.total_cores)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalFloatingIps"],
                         sot.absolute.floating_ips)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalInstances"],
                         sot.absolute.instances)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalKeypairs"],
                         sot.absolute.keypairs)
        self.assertEqual(ABSOLUTE_LIMITS["maxTotalRAMSize"],
                         sot.absolute.total_ram)
        self.assertEqual(ABSOLUTE_LIMITS["maxServerGroups"],
                         sot.absolute.server_groups)
        self.assertEqual(ABSOLUTE_LIMITS["maxServerGroupMembers"],
                         sot.absolute.server_group_members)
        self.assertEqual(ABSOLUTE_LIMITS["totalFloatingIpsUsed"],
                         sot.absolute.floating_ips_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalSecurityGroupsUsed"],
                         sot.absolute.security_groups_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalRAMUsed"],
                         sot.absolute.total_ram_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalInstancesUsed"],
                         sot.absolute.instances_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalServerGroupsUsed"],
                         sot.absolute.server_groups_used)
        self.assertEqual(ABSOLUTE_LIMITS["totalCoresUsed"],
                         sot.absolute.total_cores_used)

        self.assertEqual(RATE_LIMIT["uri"], sot.rate[0].uri)
        self.assertEqual(RATE_LIMIT["regex"], sot.rate[0].regex)
        self.assertEqual(RATE_LIMIT["limit"], sot.rate[0].limits)