Merge "port instance_usage_audit_log tests into nova v3 part2"
This commit is contained in:
@@ -276,6 +276,8 @@ class BaseV3ComputeTest(BaseComputeTest):
|
||||
cls.extensions_client = cls.os.extensions_v3_client
|
||||
cls.availability_zone_client = cls.os.availability_zone_v3_client
|
||||
cls.interfaces_client = cls.os.interfaces_v3_client
|
||||
cls.instance_usages_audit_log_client = \
|
||||
cls.os.instance_usages_audit_log_v3_client
|
||||
cls.hypervisor_client = cls.os.hypervisor_v3_client
|
||||
cls.keypairs_client = cls.os.keypairs_v3_client
|
||||
cls.tenant_usages_client = cls.os.tenant_usages_v3_client
|
||||
@@ -344,6 +346,8 @@ class BaseV3ComputeAdminTest(BaseV3ComputeTest):
|
||||
|
||||
cls.os_adm = os_adm
|
||||
cls.servers_admin_client = cls.os_adm.servers_v3_client
|
||||
cls.instance_usages_audit_log_admin_client = \
|
||||
cls.os_adm.instance_usages_audit_log_v3_client
|
||||
cls.services_admin_client = cls.os_adm.services_v3_client
|
||||
cls.availability_zone_admin_client = \
|
||||
cls.os_adm.availability_zone_v3_client
|
||||
|
||||
@@ -16,22 +16,22 @@
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
|
||||
from tempest.api.compute import base
|
||||
from tempest.test import attr
|
||||
import urllib
|
||||
|
||||
from tempest.api.compute import base
|
||||
from tempest import test
|
||||
|
||||
class InstanceUsageAuditLogTestJSON(base.BaseV2ComputeAdminTest):
|
||||
|
||||
class InstanceUsageAuditLogV3TestJSON(base.BaseV3ComputeAdminTest):
|
||||
|
||||
_interface = 'json'
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(InstanceUsageAuditLogTestJSON, cls).setUpClass()
|
||||
cls.adm_client = cls.os_adm.instance_usages_audit_log_client
|
||||
super(InstanceUsageAuditLogV3TestJSON, cls).setUpClass()
|
||||
cls.adm_client = cls.instance_usages_audit_log_admin_client
|
||||
|
||||
@attr(type='gate')
|
||||
@test.attr(type='gate')
|
||||
def test_list_instance_usage_audit_logs(self):
|
||||
# list instance usage audit logs
|
||||
resp, body = self.adm_client.list_instance_usage_audit_logs()
|
||||
@@ -44,12 +44,12 @@ class InstanceUsageAuditLogTestJSON(base.BaseV2ComputeAdminTest):
|
||||
for item in expected_items:
|
||||
self.assertIn(item, body)
|
||||
|
||||
@attr(type='gate')
|
||||
def test_get_instance_usage_audit_log(self):
|
||||
@test.attr(type='gate')
|
||||
def test_list_instance_usage_audit_logs_with_filter_before(self):
|
||||
# Get instance usage audit log before specified time
|
||||
now = datetime.datetime.now()
|
||||
resp, body = self.adm_client.get_instance_usage_audit_log(
|
||||
urllib.quote(now.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
ending_time = datetime.datetime(2012, 12, 24)
|
||||
resp, body = self.adm_client.list_instance_usage_audit_logs(
|
||||
urllib.quote(ending_time.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
self.assertEqual(200, resp.status)
|
||||
expected_items = ['total_errors', 'total_instances', 'log',
|
||||
@@ -58,7 +58,8 @@ class InstanceUsageAuditLogTestJSON(base.BaseV2ComputeAdminTest):
|
||||
'period_beginning', 'num_hosts_not_run']
|
||||
for item in expected_items:
|
||||
self.assertIn(item, body)
|
||||
self.assertEqual(body['period_ending'], "2012-12-23 23:00:00")
|
||||
|
||||
|
||||
class InstanceUsageAuditLogTestXML(InstanceUsageAuditLogTestJSON):
|
||||
class InstanceUsageAuditLogV3TestXML(InstanceUsageAuditLogV3TestJSON):
|
||||
_interface = 'xml'
|
||||
|
||||
@@ -15,42 +15,34 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
|
||||
from tempest.api.compute import base
|
||||
from tempest import exceptions
|
||||
from tempest.test import attr
|
||||
import urllib
|
||||
from tempest import test
|
||||
|
||||
|
||||
class InstanceUsageAuditLogNegativeTestJSON(base.BaseV2ComputeAdminTest):
|
||||
class InstanceUsageLogNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
|
||||
|
||||
_interface = 'json'
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(InstanceUsageAuditLogNegativeTestJSON, cls).setUpClass()
|
||||
cls.adm_client = cls.os_adm.instance_usages_audit_log_client
|
||||
super(InstanceUsageLogNegativeV3TestJSON, cls).setUpClass()
|
||||
cls.adm_client = cls.instance_usages_audit_log_admin_client
|
||||
|
||||
@attr(type=['negative', 'gate'])
|
||||
@test.attr(type=['negative', 'gate'])
|
||||
def test_instance_usage_audit_logs_with_nonadmin_user(self):
|
||||
# the instance_usage_audit_logs API just can be accessed by admin user
|
||||
self.assertRaises(exceptions.Unauthorized,
|
||||
self.instance_usages_audit_log_client.
|
||||
list_instance_usage_audit_logs)
|
||||
now = datetime.datetime.now()
|
||||
self.assertRaises(exceptions.Unauthorized,
|
||||
self.instance_usages_audit_log_client.
|
||||
get_instance_usage_audit_log,
|
||||
urllib.quote(now.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
@attr(type=['negative', 'gate'])
|
||||
@test.attr(type=['negative', 'gate'])
|
||||
def test_get_instance_usage_audit_logs_with_invalid_time(self):
|
||||
self.assertRaises(exceptions.BadRequest,
|
||||
self.adm_client.get_instance_usage_audit_log,
|
||||
self.adm_client.list_instance_usage_audit_logs,
|
||||
"invalid_time")
|
||||
|
||||
|
||||
class InstanceUsageAuditLogNegativeTestXML(
|
||||
InstanceUsageAuditLogNegativeTestJSON):
|
||||
class InstanceUsageLogNegativeV3TestXML(
|
||||
InstanceUsageLogNegativeV3TestJSON):
|
||||
_interface = 'xml'
|
||||
|
||||
@@ -64,6 +64,8 @@ from tempest.services.compute.v3.json.flavors_client import FlavorsV3ClientJSON
|
||||
from tempest.services.compute.v3.json.hosts_client import HostsV3ClientJSON
|
||||
from tempest.services.compute.v3.json.hypervisor_client import \
|
||||
HypervisorV3ClientJSON
|
||||
from tempest.services.compute.v3.json.instance_usage_audit_log_client import \
|
||||
InstanceUsagesAuditLogV3ClientJSON
|
||||
from tempest.services.compute.v3.json.interfaces_client import \
|
||||
InterfacesV3ClientJSON
|
||||
from tempest.services.compute.v3.json.keypairs_client import \
|
||||
@@ -88,6 +90,8 @@ from tempest.services.compute.v3.xml.flavors_client import FlavorsV3ClientXML
|
||||
from tempest.services.compute.v3.xml.hosts_client import HostsV3ClientXML
|
||||
from tempest.services.compute.v3.xml.hypervisor_client import \
|
||||
HypervisorV3ClientXML
|
||||
from tempest.services.compute.v3.xml.instance_usage_audit_log_client import \
|
||||
InstanceUsagesAuditLogV3ClientXML
|
||||
from tempest.services.compute.v3.xml.interfaces_client import \
|
||||
InterfacesV3ClientXML
|
||||
from tempest.services.compute.v3.xml.keypairs_client import KeyPairsV3ClientXML
|
||||
@@ -284,6 +288,8 @@ class Manager(object):
|
||||
self.credentials_client = CredentialsClientXML(*client_args)
|
||||
self.instance_usages_audit_log_client = \
|
||||
InstanceUsagesAuditLogClientXML(*client_args)
|
||||
self.instance_usages_audit_log_v3_client = \
|
||||
InstanceUsagesAuditLogV3ClientXML(*client_args)
|
||||
self.volume_hosts_client = VolumeHostsClientXML(*client_args)
|
||||
self.volumes_extension_client = VolumeExtensionClientXML(
|
||||
*client_args)
|
||||
@@ -347,6 +353,8 @@ class Manager(object):
|
||||
self.credentials_client = CredentialsClientJSON(*client_args)
|
||||
self.instance_usages_audit_log_client = \
|
||||
InstanceUsagesAuditLogClientJSON(*client_args)
|
||||
self.instance_usages_audit_log_v3_client = \
|
||||
InstanceUsagesAuditLogV3ClientJSON(*client_args)
|
||||
self.volume_hosts_client = VolumeHostsClientJSON(*client_args)
|
||||
self.volumes_extension_client = VolumeExtensionClientJSON(
|
||||
*client_args)
|
||||
|
||||
@@ -20,21 +20,18 @@ import json
|
||||
from tempest.common.rest_client import RestClient
|
||||
|
||||
|
||||
class InstanceUsagesAuditLogClientJSON(RestClient):
|
||||
class InstanceUsagesAuditLogV3ClientJSON(RestClient):
|
||||
|
||||
def __init__(self, config, username, password, auth_url, tenant_name=None):
|
||||
super(InstanceUsagesAuditLogClientJSON, self).__init__(
|
||||
super(InstanceUsagesAuditLogV3ClientJSON, self).__init__(
|
||||
config, username, password, auth_url, tenant_name)
|
||||
self.service = self.config.compute.catalog_type
|
||||
self.service = self.config.compute.catalog_v3_type
|
||||
|
||||
def list_instance_usage_audit_logs(self):
|
||||
url = 'os-instance_usage_audit_log'
|
||||
resp, body = self.get(url)
|
||||
body = json.loads(body)
|
||||
return resp, body["instance_usage_audit_logs"]
|
||||
|
||||
def get_instance_usage_audit_log(self, time_before):
|
||||
url = 'os-instance_usage_audit_log/%s' % time_before
|
||||
def list_instance_usage_audit_logs(self, time_before=None):
|
||||
if time_before:
|
||||
url = 'os-instance-usage-audit-log?before=%s' % time_before
|
||||
else:
|
||||
url = 'os-instance-usage-audit-log'
|
||||
resp, body = self.get(url)
|
||||
body = json.loads(body)
|
||||
return resp, body["instance_usage_audit_log"]
|
||||
|
||||
@@ -21,21 +21,18 @@ from tempest.common.rest_client import RestClientXML
|
||||
from tempest.services.compute.xml.common import xml_to_json
|
||||
|
||||
|
||||
class InstanceUsagesAuditLogClientXML(RestClientXML):
|
||||
class InstanceUsagesAuditLogV3ClientXML(RestClientXML):
|
||||
|
||||
def __init__(self, config, username, password, auth_url, tenant_name=None):
|
||||
super(InstanceUsagesAuditLogClientXML, self).__init__(
|
||||
super(InstanceUsagesAuditLogV3ClientXML, self).__init__(
|
||||
config, username, password, auth_url, tenant_name)
|
||||
self.service = self.config.compute.catalog_type
|
||||
self.service = self.config.compute.catalog_v3_type
|
||||
|
||||
def list_instance_usage_audit_logs(self):
|
||||
url = 'os-instance_usage_audit_log'
|
||||
def list_instance_usage_audit_logs(self, time_before=None):
|
||||
if time_before:
|
||||
url = 'os-instance-usage-audit-log?before=%s' % time_before
|
||||
else:
|
||||
url = 'os-instance-usage-audit-log'
|
||||
resp, body = self.get(url, self.headers)
|
||||
instance_usage_audit_logs = xml_to_json(etree.fromstring(body))
|
||||
return resp, instance_usage_audit_logs
|
||||
|
||||
def get_instance_usage_audit_log(self, time_before):
|
||||
url = 'os-instance_usage_audit_log/%s' % time_before
|
||||
resp, body = self.get(url, self.headers)
|
||||
instance_usage_audit_log = xml_to_json(etree.fromstring(body))
|
||||
return resp, instance_usage_audit_log
|
||||
|
||||
Reference in New Issue
Block a user