Convert remaining nova tests to requests_mock
Change-Id: Iff4341f2c83493c901f5e18570f82b0b5f7f3ad5
This commit is contained in:
parent
a2ec277bf5
commit
56244f5410
|
@ -9,26 +9,87 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import mock
|
||||
|
||||
import shade
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
class TestLimits(base.RequestsMockTestCase):
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||
def test_get_compute_limits(self, mock_nova):
|
||||
def test_get_compute_limits(self):
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public', append=['limits']),
|
||||
json={
|
||||
"limits": {
|
||||
"absolute": {
|
||||
"maxImageMeta": 128,
|
||||
"maxPersonality": 5,
|
||||
"maxPersonalitySize": 10240,
|
||||
"maxSecurityGroupRules": 20,
|
||||
"maxSecurityGroups": 10,
|
||||
"maxServerMeta": 128,
|
||||
"maxTotalCores": 20,
|
||||
"maxTotalFloatingIps": 10,
|
||||
"maxTotalInstances": 10,
|
||||
"maxTotalKeypairs": 100,
|
||||
"maxTotalRAMSize": 51200,
|
||||
"maxServerGroups": 10,
|
||||
"maxServerGroupMembers": 10,
|
||||
"totalCoresUsed": 0,
|
||||
"totalInstancesUsed": 0,
|
||||
"totalRAMUsed": 0,
|
||||
"totalSecurityGroupsUsed": 0,
|
||||
"totalFloatingIpsUsed": 0,
|
||||
"totalServerGroupsUsed": 0
|
||||
},
|
||||
"rate": []
|
||||
}
|
||||
}),
|
||||
])
|
||||
|
||||
self.cloud.get_compute_limits()
|
||||
|
||||
mock_nova.limits.get.assert_called_once_with()
|
||||
self.assert_calls()
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||
def test_other_get_compute_limits(self, mock_nova):
|
||||
def test_other_get_compute_limits(self):
|
||||
project = self.mock_for_keystone_projects(project_count=1,
|
||||
list_get=True)[0]
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public', append=['limits'],
|
||||
qs_elements=[
|
||||
'tenant_id={id}'.format(id=project.project_id)
|
||||
]),
|
||||
json={
|
||||
"limits": {
|
||||
"absolute": {
|
||||
"maxImageMeta": 128,
|
||||
"maxPersonality": 5,
|
||||
"maxPersonalitySize": 10240,
|
||||
"maxSecurityGroupRules": 20,
|
||||
"maxSecurityGroups": 10,
|
||||
"maxServerMeta": 128,
|
||||
"maxTotalCores": 20,
|
||||
"maxTotalFloatingIps": 10,
|
||||
"maxTotalInstances": 10,
|
||||
"maxTotalKeypairs": 100,
|
||||
"maxTotalRAMSize": 51200,
|
||||
"maxServerGroups": 10,
|
||||
"maxServerGroupMembers": 10,
|
||||
"totalCoresUsed": 0,
|
||||
"totalInstancesUsed": 0,
|
||||
"totalRAMUsed": 0,
|
||||
"totalSecurityGroupsUsed": 0,
|
||||
"totalFloatingIpsUsed": 0,
|
||||
"totalServerGroupsUsed": 0
|
||||
},
|
||||
"rate": []
|
||||
}
|
||||
}),
|
||||
])
|
||||
|
||||
self.op_cloud.get_compute_limits(project.project_id)
|
||||
|
||||
mock_nova.limits.get.assert_called_once_with(
|
||||
tenant_id=project.project_id)
|
||||
self.assert_calls()
|
||||
|
|
|
@ -10,63 +10,99 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import mock
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
|
||||
import shade
|
||||
from shade import exc
|
||||
from shade.tests.unit import base
|
||||
|
||||
fake_quota_set = {
|
||||
"cores": 20,
|
||||
"fixed_ips": -1,
|
||||
"floating_ips": 10,
|
||||
"injected_file_content_bytes": 10240,
|
||||
"injected_file_path_bytes": 255,
|
||||
"injected_files": 5,
|
||||
"instances": 10,
|
||||
"key_pairs": 100,
|
||||
"metadata_items": 128,
|
||||
"ram": 51200,
|
||||
"security_group_rules": 20,
|
||||
"security_groups": 45,
|
||||
"server_groups": 10,
|
||||
"server_group_members": 10
|
||||
}
|
||||
|
||||
|
||||
class TestQuotas(base.RequestsMockTestCase):
|
||||
def setUp(self, cloud_config_fixture='clouds.yaml'):
|
||||
super(TestQuotas, self).setUp(
|
||||
cloud_config_fixture=cloud_config_fixture)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||
def test_update_quotas(self, mock_nova):
|
||||
def test_update_quotas(self):
|
||||
project = self.mock_for_keystone_projects(project_count=1,
|
||||
list_get=True)[0]
|
||||
# re-mock the list-get as the call to set_compute_quotas when
|
||||
# bad-request is raised, still calls out to get the project data.
|
||||
self.mock_for_keystone_projects(project=project, list_get=True)
|
||||
|
||||
self.register_uris([
|
||||
dict(method='PUT',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public',
|
||||
append=['os-quota-sets', project.project_id]),
|
||||
json={'quota_set': fake_quota_set},
|
||||
validate=dict(
|
||||
json={
|
||||
'quota_set': {
|
||||
'cores': 1,
|
||||
'force': True
|
||||
}})),
|
||||
])
|
||||
|
||||
self.op_cloud.set_compute_quotas(project.project_id, cores=1)
|
||||
|
||||
mock_nova.quotas.update.assert_called_once_with(
|
||||
cores=1, force=True, tenant_id=project.project_id)
|
||||
|
||||
mock_nova.quotas.update.side_effect = nova_exceptions.BadRequest(400)
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.op_cloud.set_compute_quotas, project)
|
||||
self.assert_calls()
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||
def test_get_quotas(self, mock_nova):
|
||||
def test_update_quotas_bad_request(self):
|
||||
project = self.mock_for_keystone_projects(project_count=1,
|
||||
list_get=True)[0]
|
||||
|
||||
self.register_uris([
|
||||
dict(method='PUT',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public',
|
||||
append=['os-quota-sets', project.project_id]),
|
||||
status_code=400),
|
||||
])
|
||||
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.op_cloud.set_compute_quotas, project.project_id)
|
||||
|
||||
self.assert_calls()
|
||||
|
||||
def test_get_quotas(self):
|
||||
project = self.mock_for_keystone_projects(project_count=1,
|
||||
list_get=True)[0]
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public',
|
||||
append=['os-quota-sets', project.project_id]),
|
||||
json={'quota_set': fake_quota_set}),
|
||||
])
|
||||
|
||||
self.op_cloud.get_compute_quotas(project.project_id)
|
||||
|
||||
mock_nova.quotas.get.assert_called_once_with(
|
||||
tenant_id=project.project_id)
|
||||
self.assert_calls()
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||
def test_delete_quotas(self, mock_nova):
|
||||
def test_delete_quotas(self):
|
||||
project = self.mock_for_keystone_projects(project_count=1,
|
||||
list_get=True)[0]
|
||||
# re-mock the list-get as the call to set_delete_compute_quotas when
|
||||
# bad-request is raised, still calls out to get the project data.
|
||||
self.mock_for_keystone_projects(project=project, list_get=True)
|
||||
|
||||
self.register_uris([
|
||||
dict(method='DELETE',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public',
|
||||
append=['os-quota-sets', project.project_id])),
|
||||
])
|
||||
|
||||
self.op_cloud.delete_compute_quotas(project.project_id)
|
||||
|
||||
mock_nova.quotas.delete.assert_called_once_with(
|
||||
tenant_id=project.project_id)
|
||||
|
||||
mock_nova.quotas.delete.side_effect = nova_exceptions.BadRequest(400)
|
||||
self.assertRaises(exc.OpenStackCloudException,
|
||||
self.op_cloud.delete_compute_quotas, project)
|
||||
self.assert_calls()
|
||||
|
||||
def test_cinder_update_quotas(self):
|
||||
|
|
|
@ -12,21 +12,54 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import datetime
|
||||
import mock
|
||||
import uuid
|
||||
|
||||
import shade
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
class TestUsage(base.RequestsMockTestCase):
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'nova_client')
|
||||
def test_get_usage(self, mock_nova):
|
||||
def test_get_usage(self):
|
||||
project = self.mock_for_keystone_projects(project_count=1,
|
||||
list_get=True)[0]
|
||||
start = end = datetime.datetime.now()
|
||||
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public',
|
||||
append=['os-simple-tenant-usage', project.project_id],
|
||||
qs_elements=[
|
||||
'start={now}'.format(now=start.isoformat()),
|
||||
'end={now}'.format(now=end.isoformat()),
|
||||
]),
|
||||
json={"tenant_usage": {
|
||||
"server_usages": [
|
||||
{
|
||||
"ended_at": None,
|
||||
"flavor": "m1.tiny",
|
||||
"hours": 1.0,
|
||||
"instance_id": uuid.uuid4().hex,
|
||||
"local_gb": 1,
|
||||
"memory_mb": 512,
|
||||
"name": "instance-2",
|
||||
"started_at": "2012-10-08T20:10:44.541277",
|
||||
"state": "active",
|
||||
"tenant_id": "6f70656e737461636b20342065766572",
|
||||
"uptime": 3600,
|
||||
"vcpus": 1
|
||||
}
|
||||
],
|
||||
"start": "2012-10-08T20:10:44.587336",
|
||||
"stop": "2012-10-08T21:10:44.587336",
|
||||
"tenant_id": "6f70656e737461636b20342065766572",
|
||||
"total_hours": 1.0,
|
||||
"total_local_gb_usage": 1.0,
|
||||
"total_memory_mb_usage": 512.0,
|
||||
"total_vcpus_usage": 1.0
|
||||
}})
|
||||
])
|
||||
|
||||
self.op_cloud.get_compute_usage(project.project_id, start, end)
|
||||
|
||||
mock_nova.usage.get.assert_called_once_with(
|
||||
start=start, end=end, tenant_id=project.project_id)
|
||||
self.assert_calls()
|
||||
|
|
Loading…
Reference in New Issue