From e3dc9f7f0f566c233363c8391db2989568f413ab Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Fri, 7 Jun 2019 13:39:31 +0200 Subject: [PATCH] Sdk0.29 (#36) * Prepare for sdk0.29 * Update for SDK 0.29 * praise pep8 gods --- doc/source/user/proxies/volume_backup.rst | 12 +- .../osclient/auto_scaling/v1/group.py | 14 +- otcextensions/osclient/dms/v1/group.py | 4 +- otcextensions/osclient/obs/client.py | 6 - otcextensions/sdk/__init__.py | 185 ++++++--------- otcextensions/sdk/anti_ddos/v1/_proxy.py | 5 +- .../sdk/anti_ddos/v1/alert_config.py | 6 +- otcextensions/sdk/anti_ddos/v1/config.py | 4 +- otcextensions/sdk/anti_ddos/v1/floating_ip.py | 11 +- otcextensions/sdk/anti_ddos/v1/status.py | 18 +- otcextensions/sdk/auto_scaling/v1/_base.py | 38 ++- otcextensions/sdk/auto_scaling/v1/_proxy.py | 8 +- otcextensions/sdk/auto_scaling/v1/config.py | 2 +- otcextensions/sdk/auto_scaling/v1/group.py | 2 +- otcextensions/sdk/auto_scaling/v1/instance.py | 2 - otcextensions/sdk/auto_scaling/v1/policy.py | 4 +- otcextensions/sdk/cts/v1/_proxy.py | 4 +- otcextensions/sdk/cts/v1/trace.py | 7 +- otcextensions/sdk/cts/v1/tracker.py | 15 +- otcextensions/sdk/dcs/v1/_proxy.py | 5 +- otcextensions/sdk/dcs/v1/backup.py | 9 +- otcextensions/sdk/dcs/v1/config.py | 11 +- otcextensions/sdk/dcs/v1/instance.py | 13 +- otcextensions/sdk/dcs/v1/restore.py | 7 +- otcextensions/sdk/dcs/v1/statistic.py | 7 +- otcextensions/sdk/deh/v1/_proxy.py | 4 +- otcextensions/sdk/deh/v1/host.py | 11 +- otcextensions/sdk/deh/v1/host_type.py | 4 +- otcextensions/sdk/deh/v1/server.py | 4 +- otcextensions/sdk/dms/v1/_proxy.py | 9 + otcextensions/sdk/dms/v1/quota.py | 3 +- otcextensions/sdk/obs/v1/_proxy.py | 5 +- otcextensions/sdk/sdk_resource.py | 2 + otcextensions/sdk/volume_backup/v2/_proxy.py | 119 +--------- otcextensions/sdk/volume_backup/v2/backup.py | 164 ------------- .../sdk/volume_backup/v2/backup_policy.py | 12 +- .../volume_backup/volume_backup_service.py | 2 +- .../functional/sdk/test_openstacksdk_init.py | 27 +++ .../osclient/auto_scaling/v1/test_group.py | 10 +- .../tests/unit/osclient/dms/v1/test_group.py | 12 +- .../unit/sdk/anti_ddos/v1/test_floating_ip.py | 4 +- .../tests/unit/sdk/anti_ddos/v1/test_proxy.py | 10 +- .../unit/sdk/auto_scaling/v1/test_activity.py | 45 +--- .../unit/sdk/auto_scaling/v1/test_config.py | 49 +--- .../unit/sdk/auto_scaling/v1/test_group.py | 38 --- .../unit/sdk/auto_scaling/v1/test_instance.py | 4 +- .../unit/sdk/auto_scaling/v1/test_policy.py | 11 +- .../unit/sdk/auto_scaling/v1/test_proxy.py | 25 +- .../unit/sdk/auto_scaling/v1/test_quota.py | 4 +- .../tests/unit/sdk/cts/v1/test_proxy.py | 6 - .../tests/unit/sdk/cts/v1/test_tracker.py | 4 +- .../tests/unit/sdk/dcs/v1/test_config.py | 2 +- .../tests/unit/sdk/dcs/v1/test_instance.py | 4 +- .../tests/unit/sdk/dcs/v1/test_proxy.py | 8 - .../tests/unit/sdk/deh/v1/test_host.py | 4 +- .../tests/unit/sdk/deh/v1/test_host_type.py | 4 +- .../tests/unit/sdk/deh/v1/test_proxy.py | 8 - .../tests/unit/sdk/deh/v1/test_server.py | 4 +- .../unit/sdk/volume_backup/v2/test_backup.py | 222 ------------------ .../volume_backup/v2/test_backup_policy.py | 163 +------------ .../unit/sdk/volume_backup/v2/test_proxy.py | 89 +------ requirements.txt | 2 +- 62 files changed, 286 insertions(+), 1211 deletions(-) delete mode 100644 otcextensions/sdk/volume_backup/v2/backup.py create mode 100644 otcextensions/tests/functional/sdk/test_openstacksdk_init.py delete mode 100644 otcextensions/tests/unit/sdk/volume_backup/v2/test_backup.py diff --git a/doc/source/user/proxies/volume_backup.rst b/doc/source/user/proxies/volume_backup.rst index cc08e66a6..dd3e60b22 100644 --- a/doc/source/user/proxies/volume_backup.rst +++ b/doc/source/user/proxies/volume_backup.rst @@ -12,18 +12,8 @@ The VBS high-level interface is available through the ``volume_backup`` member of a :class:`~openstack.connection.Connection` object. The ``volume_backup`` member will only be added if the ``otcextensions.sdk.register_otc_extensions(conn)`` method is called. -Backup Operations -^^^^^^^^^^^^^^^^^ +The Backup itself is an OpenStack entity and supported natively as block_storage.Backup. -.. autoclass:: otcextensions.sdk.volume_backup.v2._proxy.Proxy - - .. automethod:: otcextensions.sdk.volume_backup.v2._proxy.Proxy.backups - .. automethod:: otcextensions.sdk.volume_backup.v2._proxy.Proxy.get_backup - .. automethod:: otcextensions.sdk.volume_backup.v2._proxy.Proxy.create_backup - .. automethod:: otcextensions.sdk.volume_backup.v2._proxy.Proxy.delete_backup - .. automethod:: otcextensions.sdk.volume_backup.v2._proxy.Proxy.restore_backup - .. automethod:: otcextensions.sdk.volume_backup.v2._proxy.Proxy.wait_for_backup - .. automethod:: otcextensions.sdk.volume_backup.v2._proxy.Proxy.wait_for_backup_delete Backup Policy Operations ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/otcextensions/osclient/auto_scaling/v1/group.py b/otcextensions/osclient/auto_scaling/v1/group.py index ca86257d7..cded083a7 100644 --- a/otcextensions/osclient/auto_scaling/v1/group.py +++ b/otcextensions/osclient/auto_scaling/v1/group.py @@ -181,8 +181,8 @@ def get_parser(self, prog_name): '(Repeat multiple times)') ) parser.add_argument( - '--subnetwork', - metavar='', + '--subnet', + metavar='', action='append', required=True, help=_('Network ID of the subnet' @@ -197,10 +197,10 @@ def get_parser(self, prog_name): '(Repeat multiple times)') ) parser.add_argument( - '--network_id', - metavar='', + '--router', + metavar='', required=True, - help=_('Network (VPC) ID') + help=_('Router (VPC) ID') ) parser.add_argument( '--audit_method', @@ -241,10 +241,10 @@ def take_action(self, parsed_args): args = {} args['name'] = parsed_args.name - args['vpc_id'] = parsed_args.network_id + args['vpc_id'] = parsed_args.router subnets = [] - for subnet in parsed_args.subnetwork: + for subnet in parsed_args.subnet: subnets.append({'id': subnet}) args['networks'] = subnets diff --git a/otcextensions/osclient/dms/v1/group.py b/otcextensions/osclient/dms/v1/group.py index 3523315f6..2551fbc8e 100644 --- a/otcextensions/osclient/dms/v1/group.py +++ b/otcextensions/osclient/dms/v1/group.py @@ -44,8 +44,10 @@ def get_parser(self, prog_name): def take_action(self, parsed_args): client = self.app.client_manager.dms + queue = client.find_queue(parsed_args.queue) + data = client.groups( - queue=parsed_args.queue, + queue=queue.id, include_deadletter=parsed_args.include_deadletter) if parsed_args.include_deadletter: diff --git a/otcextensions/osclient/obs/client.py b/otcextensions/osclient/obs/client.py index 66b81b00f..23ed0f8d7 100644 --- a/otcextensions/osclient/obs/client.py +++ b/otcextensions/osclient/obs/client.py @@ -20,12 +20,6 @@ DEFAULT_API_VERSION = '1' -OBS_API_TYPE = 'object' -OBS_API_SERVICE_NAME = 'objectstorage' -OBS_API_VERSIONS = { - '1': 'otcextensions.obs.v1.api.API', -} - API_VERSION_OPTION = 'os_obs_api_version' API_NAME = "obs" API_VERSIONS = { diff --git a/otcextensions/sdk/__init__.py b/otcextensions/sdk/__init__.py index 11ce638be..58150c703 100644 --- a/otcextensions/sdk/__init__.py +++ b/otcextensions/sdk/__init__.py @@ -11,12 +11,8 @@ # under the License. import importlib import os -import types -import warnings from openstack import _log -from openstack import connection -from openstack import service_description from openstack import utils @@ -81,7 +77,6 @@ 'dns': { 'service_type': 'dns', 'replace_system': True, - # 'append_project_id': True, }, 'kms': { 'service_type': 'kms', @@ -91,6 +86,7 @@ 'service_type': 'obs', 'require_ak': True, 'endpoint_service_type': 'object', + 'set_endpoint_override': True }, 'rds': { 'service_type': 'rds', @@ -98,8 +94,9 @@ 'append_project_id': True, }, 'volume_backup': { - 'service_type': 'vbs', + 'service_type': 'volume_backup', 'append_project_id': True, + 'endpoint_service_type': 'vbs', }, } @@ -115,8 +112,8 @@ def _get_descriptor(service_name): desc_class = _find_service_description_class(service_type) # _logger.debug('descriptor class %s' % desc_class) descriptor_args = { - 'service_type': service.get('endpoint_service_type', service_type) - # 'service_type': service_type + 'service_type': service.get('endpoint_service_type', service_type), + 'aliases': [service.get('service_type', service_type)] } if not desc_class.supported_versions: @@ -155,121 +152,95 @@ def _find_service_description_class(service_type): module_name = service_type.replace('-', '_') + '_service' class_name = ''.join( [part.capitalize() for part in module_name.split('_')]) - try: - import_name = '.'.join([package_name, module_name]) - service_description_module = importlib.import_module(import_name) - except ImportError as e: - # ImportWarning is ignored by default. This warning is here - # as an opt-in for people trying to figure out why something - # didn't work. - warnings.warn( - "Could not import {service_type} service description: {e}".format( - service_type=service_type, e=str(e)), - ImportWarning) - return service_description.ServiceDescription + # try: + import_name = '.'.join([package_name, module_name]) + service_description_module = importlib.import_module(import_name) + # except ImportError as e: + # # ImportWarning is ignored by default. This warning is here + # # as an opt-in for people trying to figure out why something + # # didn't work. + # _logger.warn("Could not import {service_type} " + # "service description: {e}".format( + # service_type=service_type, e=str(e)), + # ImportWarning) + # return service_description.ServiceDescription # There are no cases in which we should have a module but not the class # inside it. service_description_class = getattr(service_description_module, class_name) return service_description_class -def patch_connection(target): - # descriptors are not working out of box for runtime attributes - # So we need to inject them. Additionally we need to override some - # properties of the proxy - - def get_otc_proxy(self, service_name=None, service=None): - _logger.debug('get_otc_proxy is %s, %s, %s' % - (self, service_name, service)) - - if service['service_type'] not in self._proxies: - # Initialize proxy and inject required properties - descriptor = _get_descriptor(service_name) - if not descriptor: - _logger.error('descriptor for service %s is missing' % - service_name) - return - - proxy = descriptor.__get__(self, descriptor) - - # Set additional_headers into the proxy - if 'additional_headers' in service: - proxy.additional_headers = service.get('additional_headers') - - # If service requires AK/SK - inject them - if service.get('require_ak', False): - _logger.debug('during registration found that ak is required') - config = self.config.config - - ak = config.get('ak', None) - sk = config.get('sk', None) - - if not ak: - ak = os.getenv('S3_ACCESS_KEY_ID', None) - if not sk: - sk = os.getenv('S3_SECRET_ACCESS_KEY', None) - - if ak and sk: - proxy._set_ak(ak=ak, sk=sk) - else: - _logger.error('AK/SK pair is not available') - return - - # Set endpoint_override - endpoint_override = service.get('endpoint_override', None) - if endpoint_override: - _logger.debug('Setting endpoint_override into the %s.Proxy' % - service_name) - proxy.endpoint_override = endpoint_override - - # Ensure EP contain %project_id - append_project_id = service.get('append_project_id', False) - if append_project_id: - ep = proxy.get_endpoint_data().catalog_url - project_id = proxy.get_project_id() - if ep and not ep.rstrip('/').endswith('\\%(project_id)s') \ - and not ep.rstrip('/').endswith('$(tenant_id)s') \ - and not ep.rstrip('/').endswith(project_id): - proxy.endpoint_override = \ - utils.urljoin(ep, '%(project_id)s') - else: - proxy = self._proxies[service['service_type']] - - return proxy - - connection.Connection.get_otc_proxy = types.MethodType( - get_otc_proxy, target) - - -def inject_service_to_sdk(conn, service_name, service): - """Inject service into the SDK space - - For some reason it should be a separate function - """ - setattr( - conn.__class__, - service_name, - property( - fget=lambda self: self.get_otc_proxy(service_name, service) - ) - ) - - -def register_otc_extensions(conn, **kwargs): +def load(conn, **kwargs): """Register supported OTC services and make them known to the OpenStackSDK :param conn: An established OpenStack cloud connection :returns: none """ - patch_connection(conn) + conn.authorize() + project_id = conn._get_project_info().id for (service_name, service) in OTC_SERVICES.items(): _logger.debug('trying to register service %s' % service_name) if service.get('replace_system', False): - conn._proxies.pop(service_name, None) - - inject_service_to_sdk(conn, service_name, service) + # system_proxy = getattr(conn, service['service_type']) + # for service_type in system_proxy.all_types: + if service['service_type'] in conn._proxies: + del conn._proxies[service['service_type']] + # print(hasattr(conn, service_name)) + # delattr(conn, service['service_type']) + + sd = _get_descriptor(service_name) + + conn.add_service(sd) + + if service.get('append_project_id', False): + # If service requires project_id, but it is not present in the + # service catalog - set endpoint_override + ep = conn.endpoint_for(sd.service_type) + if ep and not ep.rstrip('/').endswith('\\%(project_id)s') \ + and not ep.rstrip('/').endswith('$(tenant_id)s') \ + and not ep.rstrip('/').endswith(project_id): + conn.config.config[ + '_'.join([ + sd.service_type.lower().replace('-', '_'), + 'endpoint_override' + ]) + ] = utils.urljoin(ep, '%(project_id)s') + elif service.get('set_endpoint_override', False): + # We need to set endpoint_override for OBS, since otherwise it + # fails dramatically + ep = conn.endpoint_for(sd.service_type) + conn.config.config[ + '_'.join([ + sd.service_type.lower().replace('-', '_'), + 'endpoint_override' + ]) + ] = utils.urljoin(ep) + + # If service requires AK/SK - inject them + if service.get('require_ak', False): + _logger.debug('during registration found that ak is required') + config = conn.config.config + + proxy = getattr(conn, service_name) + + ak = config.get('ak', None) + sk = config.get('sk', None) + + if not ak: + ak = os.getenv('S3_ACCESS_KEY_ID', None) + if not sk: + sk = os.getenv('S3_SECRET_ACCESS_KEY', None) + + if ak and sk: + proxy._set_ak(ak=ak, sk=sk) + else: + _logger.error('AK/SK pair is not available') + # return return None + + +register_otc_extensions = load diff --git a/otcextensions/sdk/anti_ddos/v1/_proxy.py b/otcextensions/sdk/anti_ddos/v1/_proxy.py index 4d7fd31e4..b8d02550e 100644 --- a/otcextensions/sdk/anti_ddos/v1/_proxy.py +++ b/otcextensions/sdk/anti_ddos/v1/_proxy.py @@ -10,15 +10,14 @@ # License for the specific language governing permissions and limitations # under the License. -# from openstack import proxy -from otcextensions.sdk import sdk_proxy +from openstack import proxy from otcextensions.sdk.anti_ddos.v1 import alert_config as _alert from otcextensions.sdk.anti_ddos.v1 import config as _config from otcextensions.sdk.anti_ddos.v1 import floating_ip as _floating_ip from otcextensions.sdk.anti_ddos.v1 import status as _status -class Proxy(sdk_proxy.Proxy): +class Proxy(proxy.Proxy): skip_discovery = True diff --git a/otcextensions/sdk/anti_ddos/v1/alert_config.py b/otcextensions/sdk/anti_ddos/v1/alert_config.py index 3334b710b..516111530 100644 --- a/otcextensions/sdk/anti_ddos/v1/alert_config.py +++ b/otcextensions/sdk/anti_ddos/v1/alert_config.py @@ -11,15 +11,13 @@ # under the License. from openstack import resource -from otcextensions.sdk import sdk_resource - -class AlertConfig(sdk_resource.Resource): +class AlertConfig(resource.Resource): base_path = '/warnalert/alertconfig/query' # capabilities - allow_get = True + allow_fetch = True # Properties #: warn alert config information diff --git a/otcextensions/sdk/anti_ddos/v1/config.py b/otcextensions/sdk/anti_ddos/v1/config.py index a32639945..69300f765 100644 --- a/otcextensions/sdk/anti_ddos/v1/config.py +++ b/otcextensions/sdk/anti_ddos/v1/config.py @@ -11,10 +11,8 @@ # under the License. from openstack import resource -from otcextensions.sdk import sdk_resource - -class Config(sdk_resource.Resource): +class Config(resource.Resource): base_path = '/antiddos/query_config_list' diff --git a/otcextensions/sdk/anti_ddos/v1/floating_ip.py b/otcextensions/sdk/anti_ddos/v1/floating_ip.py index f7adf9d69..bc0a9a90b 100644 --- a/otcextensions/sdk/anti_ddos/v1/floating_ip.py +++ b/otcextensions/sdk/anti_ddos/v1/floating_ip.py @@ -10,23 +10,18 @@ # License for the specific language governing permissions and limitations # under the License. from openstack import resource -from openstack import _log -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - - -class FloatingIP(sdk_resource.Resource): +class FloatingIP(resource.Resource): resources_key = 'ddosStatus' base_path = '/antiddos' # capabilities allow_list = True - allow_get = True + allow_fetch = True allow_delete = True - allow_update = True + allow_commit = True _query_mapping = resource.QueryParameters('status', 'limit', diff --git a/otcextensions/sdk/anti_ddos/v1/status.py b/otcextensions/sdk/anti_ddos/v1/status.py index 88a4ea54e..8e2d1a699 100644 --- a/otcextensions/sdk/anti_ddos/v1/status.py +++ b/otcextensions/sdk/anti_ddos/v1/status.py @@ -10,20 +10,16 @@ # License for the specific language governing permissions and limitations # under the License. from openstack import resource -from openstack import _log from otcextensions.common import format -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - -class TaskStatus(sdk_resource.Resource): +class TaskStatus(resource.Resource): base_path = '/query_task_status' # capabilities - allow_get = True + allow_fetch = True _query_mapping = resource.QueryParameters('task_id') @@ -35,7 +31,7 @@ class TaskStatus(sdk_resource.Resource): task_msg = resource.Body('task_msg') -class FloatingIPStatus(sdk_resource.Resource): +class FloatingIPStatus(resource.Resource): base_path = '/antiddos/%(floating_ip_id)s/status' @@ -50,7 +46,7 @@ class FloatingIPStatus(sdk_resource.Resource): status = resource.Body('status') -class FloatingIPEvent(sdk_resource.Resource): +class FloatingIPEvent(resource.Resource): resources_key = 'logs' base_path = '/antiddos/%(floating_ip_id)s/logs' @@ -85,7 +81,7 @@ class FloatingIPEvent(sdk_resource.Resource): trigger_http_pps = resource.Body('trigger_http_pps', type=int) -class FloatingIPDayStat(sdk_resource.Resource): +class FloatingIPDayStat(resource.Resource): resources_key = 'data' base_path = '/antiddos/%(floating_ip_id)s/daily' @@ -117,7 +113,7 @@ class FloatingIPDayStat(sdk_resource.Resource): total_pps = resource.Body('total_pps', type=int) -class FloatingIPWeekStatData(sdk_resource.Resource): +class FloatingIPWeekStatData(resource.Resource): # Properties #: Intercept time in one week #: *Type: int* @@ -134,7 +130,7 @@ class FloatingIPWeekStatData(sdk_resource.Resource): type=format.TimeTMsStr) -class FloatingIPWeekStat(sdk_resource.Resource): +class FloatingIPWeekStat(resource.Resource): base_path = '/antiddos/weekly' diff --git a/otcextensions/sdk/auto_scaling/v1/_base.py b/otcextensions/sdk/auto_scaling/v1/_base.py index 367137af9..fbab46463 100644 --- a/otcextensions/sdk/auto_scaling/v1/_base.py +++ b/otcextensions/sdk/auto_scaling/v1/_base.py @@ -13,10 +13,8 @@ from openstack import resource from openstack import utils -from otcextensions.sdk import sdk_resource - -class Resource(sdk_resource.Resource): +class Resource(resource.Resource): query_marker_key = 'start_number' @@ -51,6 +49,40 @@ def find_value_by_accessor(input_dict, accessor): return None return current_data + @classmethod + def _prepare_override_args(cls, + endpoint_override=None, + request_headers=None, + additional_headers=None, + requests_auth=None): + """Prepare additional (override) arguments for the REST call + + :param endpoint_override: optional endpoint_override argument + :param request_headers: original calculated request headers + :param additional_headers: additional headers to be set into request + + :returns arguments dict + """ + req_args = {} + + if additional_headers and request_headers: + req_args['headers'] = utils.merge_two_dicts( + additional_headers, + request_headers) + else: + if additional_headers: + req_args['headers'] = additional_headers + if request_headers: + req_args['headers'] = request_headers + + if endpoint_override: + req_args['endpoint_override'] = endpoint_override + + if requests_auth: + req_args['requests_auth'] = requests_auth + + return req_args + # Due to the other LIST url need to override # It is not efficient (as of implementation) to extend general list # with support of other url just for one service diff --git a/otcextensions/sdk/auto_scaling/v1/_proxy.py b/otcextensions/sdk/auto_scaling/v1/_proxy.py index 823fc2124..8da39e6eb 100644 --- a/otcextensions/sdk/auto_scaling/v1/_proxy.py +++ b/otcextensions/sdk/auto_scaling/v1/_proxy.py @@ -9,9 +9,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from openstack import _log - -from otcextensions.sdk import sdk_proxy +from openstack import proxy from otcextensions.sdk.auto_scaling.v1 import activity as _activity from otcextensions.sdk.auto_scaling.v1 import config as _config from otcextensions.sdk.auto_scaling.v1 import group as _group @@ -19,10 +17,8 @@ from otcextensions.sdk.auto_scaling.v1 import policy as _policy from otcextensions.sdk.auto_scaling.v1 import quota as _quota -_logger = _log.setup_logging('openstack') - -class Proxy(sdk_proxy.Proxy): +class Proxy(proxy.Proxy): skip_discovery = True diff --git a/otcextensions/sdk/auto_scaling/v1/config.py b/otcextensions/sdk/auto_scaling/v1/config.py index be04ed4e9..8132d3c3e 100644 --- a/otcextensions/sdk/auto_scaling/v1/config.py +++ b/otcextensions/sdk/auto_scaling/v1/config.py @@ -60,7 +60,7 @@ class Config(_base.Resource): # capabilities allow_create = True allow_list = True - allow_get = True + allow_fetch = True allow_delete = True # _query_mapping = resource.QueryParameters( diff --git a/otcextensions/sdk/auto_scaling/v1/group.py b/otcextensions/sdk/auto_scaling/v1/group.py index 92473edcc..71de34835 100644 --- a/otcextensions/sdk/auto_scaling/v1/group.py +++ b/otcextensions/sdk/auto_scaling/v1/group.py @@ -24,7 +24,7 @@ class Group(_base.Resource): # capabilities allow_create = True allow_list = True - allow_get = True + allow_fetch = True allow_delete = True allow_update = True diff --git a/otcextensions/sdk/auto_scaling/v1/instance.py b/otcextensions/sdk/auto_scaling/v1/instance.py index 2e35e5c07..b1f3fb9b6 100644 --- a/otcextensions/sdk/auto_scaling/v1/instance.py +++ b/otcextensions/sdk/auto_scaling/v1/instance.py @@ -29,9 +29,7 @@ class Instance(_base.Resource): query_marker_key = 'start_number' # capabilities - allow_create = False allow_list = True - allow_get = False allow_delete = True _query_mapping = resource.QueryParameters( diff --git a/otcextensions/sdk/auto_scaling/v1/policy.py b/otcextensions/sdk/auto_scaling/v1/policy.py index 043339f4e..08fc357a5 100644 --- a/otcextensions/sdk/auto_scaling/v1/policy.py +++ b/otcextensions/sdk/auto_scaling/v1/policy.py @@ -56,9 +56,9 @@ class Policy(_base.Resource): # capabilities allow_create = True allow_list = True - allow_get = True + allow_fetch = True allow_delete = True - allow_update = True + allow_commit = True _query_mapping = resource.QueryParameters( 'limit', 'name', 'type', 'marker', diff --git a/otcextensions/sdk/cts/v1/_proxy.py b/otcextensions/sdk/cts/v1/_proxy.py index 5227f5768..419bcf781 100644 --- a/otcextensions/sdk/cts/v1/_proxy.py +++ b/otcextensions/sdk/cts/v1/_proxy.py @@ -9,13 +9,13 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from otcextensions.sdk import sdk_proxy +from openstack import proxy from otcextensions.sdk.cts.v1 import tracker as _tracker from otcextensions.sdk.cts.v1 import trace as _trace -class Proxy(sdk_proxy.Proxy): +class Proxy(proxy.Proxy): skip_discovery = True diff --git a/otcextensions/sdk/cts/v1/trace.py b/otcextensions/sdk/cts/v1/trace.py index 29baeae3f..5d10fadaf 100644 --- a/otcextensions/sdk/cts/v1/trace.py +++ b/otcextensions/sdk/cts/v1/trace.py @@ -11,16 +11,11 @@ # under the License. from openstack import resource -from openstack import _log from otcextensions.common import format -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - - -class Trace(sdk_resource.Resource): +class Trace(resource.Resource): base_path = '/%(tracker_name)s/trace' resources_key = 'traces' diff --git a/otcextensions/sdk/cts/v1/tracker.py b/otcextensions/sdk/cts/v1/tracker.py index 1926f2f49..689607887 100644 --- a/otcextensions/sdk/cts/v1/tracker.py +++ b/otcextensions/sdk/cts/v1/tracker.py @@ -10,16 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. from openstack import resource -from openstack import _log from otcextensions.common import exc -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - - -class Smn(sdk_resource.Resource): +class Smn(resource.Resource): #: Specifies whether SMN is supported. enabled = resource.Body('is_support_smn', type=bool) #: Specifies the theme of the SMN service. @@ -47,7 +42,7 @@ class Smn(sdk_resource.Resource): notify_users = resource.Body('need_notify_user_list', type=list) -class Tracker(sdk_resource.Resource): +class Tracker(resource.Resource): base_path = '/tracker' @@ -55,8 +50,8 @@ class Tracker(sdk_resource.Resource): # capabilities allow_create = True - allow_update = True - allow_get = True + allow_commit = True + allow_fetch = True allow_delete = True # Properties @@ -89,7 +84,7 @@ def _translate_response(self, response, has_body=None, error_message=None): if has_body: if response.status_code == 204: # Some bad APIs (i.e. DCS.Backup.List) return emptiness - _logger.warn('API returned no content, while it was expected') + self.log.warn('API returned no content, while it was expected') return # NOTE: in difference to doc "GET" method return list with 1 item body = response.json() diff --git a/otcextensions/sdk/dcs/v1/_proxy.py b/otcextensions/sdk/dcs/v1/_proxy.py index 2f95ef2c8..35aa86a1b 100644 --- a/otcextensions/sdk/dcs/v1/_proxy.py +++ b/otcextensions/sdk/dcs/v1/_proxy.py @@ -10,8 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -# from openstack import proxy -from otcextensions.sdk import sdk_proxy +from openstack import proxy from otcextensions.sdk.dcs.v1 import backup as _backup from otcextensions.sdk.dcs.v1 import config as _config from otcextensions.sdk.dcs.v1 import instance as _instance @@ -19,7 +18,7 @@ from otcextensions.sdk.dcs.v1 import statistic as _stat -class Proxy(sdk_proxy.Proxy): +class Proxy(proxy.Proxy): skip_discovery = True diff --git a/otcextensions/sdk/dcs/v1/backup.py b/otcextensions/sdk/dcs/v1/backup.py index 73b4a4189..669dde74e 100644 --- a/otcextensions/sdk/dcs/v1/backup.py +++ b/otcextensions/sdk/dcs/v1/backup.py @@ -10,11 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. from openstack import resource -from openstack import _log - -from otcextensions.sdk import sdk_resource - -_logger = _log.setup_logging('openstack') class DcsBool(object): @@ -40,7 +35,7 @@ def __eq__(self, other): return self.val == other -class Backup(sdk_resource.Resource): +class Backup(resource.Resource): resources_key = 'backup_record_response' @@ -49,7 +44,7 @@ class Backup(sdk_resource.Resource): # capabilities allow_create = True allow_list = True - allow_get = True + allow_fetch = True allow_delete = True _query_mapping = resource.QueryParameters( diff --git a/otcextensions/sdk/dcs/v1/config.py b/otcextensions/sdk/dcs/v1/config.py index 1e929abc5..e8e01b567 100644 --- a/otcextensions/sdk/dcs/v1/config.py +++ b/otcextensions/sdk/dcs/v1/config.py @@ -9,15 +9,10 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from openstack import _log from openstack import resource -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - - -class Config(sdk_resource.Resource): +class Config(resource.Resource): resources_key = 'redis_config' @@ -25,8 +20,8 @@ class Config(sdk_resource.Resource): # capabilities allow_list = True - allow_update = True - update_method = "PUT" + allow_commit = True + commit_method = "PUT" # Properties #: Instance ID diff --git a/otcextensions/sdk/dcs/v1/instance.py b/otcextensions/sdk/dcs/v1/instance.py index 188d93fb9..d729ac073 100644 --- a/otcextensions/sdk/dcs/v1/instance.py +++ b/otcextensions/sdk/dcs/v1/instance.py @@ -12,14 +12,9 @@ from openstack import exceptions from openstack import resource from openstack import utils -from openstack import _log -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - - -class Instance(sdk_resource.Resource): +class Instance(resource.Resource): resources_key = 'instances' @@ -28,9 +23,7 @@ class Instance(sdk_resource.Resource): # capabilities allow_create = True allow_list = True - allow_get = True allow_delete = True - allow_update = True allow_fetch = True allow_commit = True @@ -133,8 +126,8 @@ def find(cls, session, name_or_id, ignore_missing=True, **params): return match.get(session) except (exceptions.NotFoundException, exceptions.HttpException, exceptions.MethodNotSupported, exceptions.BadRequestException): - _logger.warn('Please specify instance ID if known for ' - 'better performance') + session.log.warn('Please specify instance ID if known for ' + 'better performance') data = cls.list(session, **params) diff --git a/otcextensions/sdk/dcs/v1/restore.py b/otcextensions/sdk/dcs/v1/restore.py index feb45d819..7e7485a85 100644 --- a/otcextensions/sdk/dcs/v1/restore.py +++ b/otcextensions/sdk/dcs/v1/restore.py @@ -10,14 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. from openstack import resource -from openstack import _log -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - - -class Restore(sdk_resource.Resource): +class Restore(resource.Resource): resources_key = 'restore_record_response' diff --git a/otcextensions/sdk/dcs/v1/statistic.py b/otcextensions/sdk/dcs/v1/statistic.py index d55fc6e51..82d15a14b 100644 --- a/otcextensions/sdk/dcs/v1/statistic.py +++ b/otcextensions/sdk/dcs/v1/statistic.py @@ -10,14 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. from openstack import resource -from openstack import _log -from otcextensions.sdk import sdk_resource -_logger = _log.setup_logging('openstack') - - -class Statistic(sdk_resource.Resource): +class Statistic(resource.Resource): resources_key = 'statistics' diff --git a/otcextensions/sdk/deh/v1/_proxy.py b/otcextensions/sdk/deh/v1/_proxy.py index 2c9436aa9..78b1c1be8 100644 --- a/otcextensions/sdk/deh/v1/_proxy.py +++ b/otcextensions/sdk/deh/v1/_proxy.py @@ -9,13 +9,13 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from otcextensions.sdk import sdk_proxy +from openstack import proxy from otcextensions.sdk.deh.v1 import host as _host from otcextensions.sdk.deh.v1 import server as _server from otcextensions.sdk.deh.v1 import host_type as _host_type -class Proxy(sdk_proxy.Proxy): +class Proxy(proxy.Proxy): skip_discovery = True diff --git a/otcextensions/sdk/deh/v1/host.py b/otcextensions/sdk/deh/v1/host.py index ad270db69..16ce95fb9 100644 --- a/otcextensions/sdk/deh/v1/host.py +++ b/otcextensions/sdk/deh/v1/host.py @@ -10,11 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. from openstack import resource -from openstack import _log - -from otcextensions.sdk import sdk_resource - -_logger = _log.setup_logging('openstack') class HostInstanceCapacity(resource.Resource): @@ -42,7 +37,7 @@ class HostProperties(resource.Resource): vcpus = resource.Body('vcpus', type=int) -class Host(sdk_resource.Resource): +class Host(resource.Resource): resource_key = 'dedicated_host' resources_key = 'dedicated_hosts' base_path = '/dedicated-hosts' @@ -50,9 +45,9 @@ class Host(sdk_resource.Resource): # capabilities allow_create = True allow_list = True - allow_get = True + allow_fetch = True allow_delete = True - allow_update = True + allow_commit = True _query_mapping = resource.QueryParameters( 'id', 'name', 'host_type', 'host_type_name', diff --git a/otcextensions/sdk/deh/v1/host_type.py b/otcextensions/sdk/deh/v1/host_type.py index 1e767544f..8f5c89a59 100644 --- a/otcextensions/sdk/deh/v1/host_type.py +++ b/otcextensions/sdk/deh/v1/host_type.py @@ -11,10 +11,8 @@ # under the License. from openstack import resource -from otcextensions.sdk import sdk_resource - -class HostType(sdk_resource.Resource): +class HostType(resource.Resource): resource_key = '' resources_key = 'dedicated_host_types' base_path = '/availability-zone/%(availability_zone)s/dedicated-host-types' diff --git a/otcextensions/sdk/deh/v1/server.py b/otcextensions/sdk/deh/v1/server.py index 5868f25f0..6f82fe0c1 100644 --- a/otcextensions/sdk/deh/v1/server.py +++ b/otcextensions/sdk/deh/v1/server.py @@ -11,10 +11,8 @@ # under the License. from openstack import resource -from otcextensions.sdk import sdk_resource - -class Server(sdk_resource.Resource): +class Server(resource.Resource): resource_key = '' resources_key = 'servers' base_path = '/dedicated-hosts/%(dedicated_host_id)s/servers' diff --git a/otcextensions/sdk/dms/v1/_proxy.py b/otcextensions/sdk/dms/v1/_proxy.py index cdbc33e09..bf9ebe118 100644 --- a/otcextensions/sdk/dms/v1/_proxy.py +++ b/otcextensions/sdk/dms/v1/_proxy.py @@ -39,6 +39,15 @@ def queues(self): """ return self._list(_queue.Queue, paginated=False) + def find_queue(self, name_or_id): + """Find queue by name or id + + :param name_or_id: Name or ID + :returns: one object of class + :class:`~otcextensions.sdk.dms.v1.queue.Queue` + """ + return self._find(_queue.Queue, name_or_id) + def get_queue(self, queue): """Get detail about a given queue id diff --git a/otcextensions/sdk/dms/v1/quota.py b/otcextensions/sdk/dms/v1/quota.py index 6603dba39..41a554e51 100644 --- a/otcextensions/sdk/dms/v1/quota.py +++ b/otcextensions/sdk/dms/v1/quota.py @@ -40,7 +40,8 @@ class Quota(_base.Resource): @classmethod def list(cls, session, paginated=False, - endpoint_override=None, headers=None, **params): + endpoint_override=None, headers=None, requests_auth=None, + **params): return super(Quota, cls).list_ext( session, paginated, endpoint_override, headers, diff --git a/otcextensions/sdk/obs/v1/_proxy.py b/otcextensions/sdk/obs/v1/_proxy.py index e9f1a7ecc..d149ce815 100644 --- a/otcextensions/sdk/obs/v1/_proxy.py +++ b/otcextensions/sdk/obs/v1/_proxy.py @@ -9,7 +9,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from openstack import _log from otcextensions.sdk import ak_auth from otcextensions.sdk import sdk_proxy @@ -17,8 +16,6 @@ from otcextensions.sdk.obs.v1 import container as _container from otcextensions.sdk.obs.v1 import obj as _obj -_logger = _log.setup_logging('openstack') - def _normalize_obs_keys(obj): return {k.lower(): v for k, v in obj.items()} @@ -35,7 +32,7 @@ def _set_ak(self, ak, sk): """Inject AK/SK into the proxy for use """ - _logger.debug('injecting ak/sk') + self.log.debug('injecting ak/sk') setattr(self, 'AK', ak) setattr(self, 'SK', sk) diff --git a/otcextensions/sdk/sdk_resource.py b/otcextensions/sdk/sdk_resource.py index 17791ad14..8c62b4448 100644 --- a/otcextensions/sdk/sdk_resource.py +++ b/otcextensions/sdk/sdk_resource.py @@ -463,6 +463,8 @@ def list_ext(cls, session, paginated=False, if scaling_group_id: uri_params = {'scaling_group_id': scaling_group_id} + print('got params %s' % params) + cls._query_mapping._validate(params, base_path=cls.base_path) query_params = cls._query_mapping._transpose(params) uri = None diff --git a/otcextensions/sdk/volume_backup/v2/_proxy.py b/otcextensions/sdk/volume_backup/v2/_proxy.py index 7e2694b34..6e17bf396 100644 --- a/otcextensions/sdk/volume_backup/v2/_proxy.py +++ b/otcextensions/sdk/volume_backup/v2/_proxy.py @@ -9,128 +9,15 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from openstack import resource - -from otcextensions.sdk import sdk_proxy -from otcextensions.sdk.volume_backup.v2 import backup as _backup +from openstack import proxy from otcextensions.sdk.volume_backup.v2 import backup_policy as _backup_policy from otcextensions.sdk.volume_backup.v2 import backup_task as _backup_task from otcextensions.sdk.volume_backup.v2 import job as _job -class Proxy(sdk_proxy.Proxy): - - # ======== Backup ======== - def backups(self, details=False, **query): - """Retrieve a generator of backups - - :param bool details: When ``True``, returns - :class:`~otcextensions.sdk.volume_backup.v2.backup.BackupDetail` - objects, otherwise - :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup`. - *Default: ``False``* - :param dict query: Optional query parameters to be sent to limit the - resources being returned: - * ``name``: backup name - * ``status``: backup status : - ``available``, ``error``, ``restoring``, ``creating``, - ``deleting``, ``error_restoring`` - * ``volume_id``: backup of volume - * ``offset``: pagination marker - * ``limit``: pagination limit - - :returns: A generator of backup - (:class:`~otcextensions.sdk.volume_backup.v2.backup.Backup`) - instances - """ - return self._list( - _backup.Backup, - paginated=True, - details=details, - **query) - - def get_backup(self, backup): - """Get a backup - - :param backup: The value can be the ID of a backup - or a :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - instance. - :returns: Backup instance - :rtype: :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - """ - return self._get(_backup.Backup, backup) - - def create_backup(self, **attrs): - """Create a new Backup from attributes with native API - - :param dict attrs: Keyword arguments which will be used to create - a :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - comprised of the properties on the Backup class. - :returns: The results of Backup creation - :rtype: :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - """ - return self._create(_backup.Backup, **attrs) - - def delete_backup(self, backup, ignore_missing=True): - """Delete a CloudBackup +class Proxy(proxy.Proxy): - :param backup: The value can be the ID of a backup or a :class:` - ~otcextensions.sdk.volume_backup.v2.backup.Backup` instance - :param bool ignore_missing: When set to ``False`` - :class:`~openstack.exceptions.ResourceNotFound` will be raised when - the zone does not exist. - When set to ``True``, no exception will be set when attempting to - delete a nonexistent zone. - - :returns: rsync job - :rtype: :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - """ - return self._delete(_backup.Backup, - backup, - ignore_missing=ignore_missing) - - def restore_backup(self, backup, volume_id): - """Restore a Backup to volume - - :param backup: The value can be the ID of a zone or a :class:` - ~otcextensions.sdk.volume_backup.v2.backup.Backup` instance - :param volume_id: the volume to restore to - :returns: A sync Job of restore backup - :rtype: :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - """ - backup = self._get_resource(_backup.Backup, backup) - return backup.restore(self, volume_id) - - def wait_for_backup(self, backup, status='available', failures=['error'], - interval=2, wait=120): - """Wait for the backup appear with the asked status - - :param backup: The value can be the ID of a backup or a :class:` - ~otcextensions.sdk.volume_backup.v2.backup.Backup` instance - :param status: requested Status to be waited for. - :param failures: status of failure - :param interval: interval for a check - :param wait: maximal time in secods to wait for the backup - - :returns: Backup object - :rtype: :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - """ - return resource.wait_for_status( - self, backup, status, failures, interval, wait) - - def wait_for_backup_delete(self, backup, interval=2, wait=120): - """Wait for the backup be deleted - - :param backup: The value can be the ID of a backup or a :class:` - ~otcextensions.sdk.volume_backup.v2.backup.Backup` instance - :param interval: interval for a check - :param wait: maximal time in secods to wait for the backup - - :returns: Backup object - :rtype: :class:`~otcextensions.sdk.volume_backup.v2.backup.Backup` - """ - return resource.wait_for_delete( - self, backup, interval, wait) + skip_discovery = True # ======== Backup Policy ======== def backup_policies(self): diff --git a/otcextensions/sdk/volume_backup/v2/backup.py b/otcextensions/sdk/volume_backup/v2/backup.py deleted file mode 100644 index d2b436359..000000000 --- a/otcextensions/sdk/volume_backup/v2/backup.py +++ /dev/null @@ -1,164 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -from openstack import exceptions -from openstack import resource -from openstack import utils - -from otcextensions.sdk import sdk_resource - - -class Backup(sdk_resource.Resource): - """Volume Backup""" - resource_key = "backup" - resources_key = "backups" - base_path = "/backups" - details_list_path = "/backups/detail" - - _query_mapping = resource.QueryParameters( - 'all_tenants', 'name', 'status', 'project_id') - - # capabilities - allow_create = True - allow_delete = True - allow_list = True - allow_get = True - - #: Properties - #: The volume to be backup - volume_id = resource.Body("volume_id") - #: The snapshot of volume which will be backup - snapshot_id = resource.Body("snapshot_id") - #: Indicates whether the backup mode is incremental. - #: If this value is true, the backup mode is incremental. - #: If this value is false, the backup mode is full. - is_incremental = resource.Body("is_incremental", type=bool) - #: Force backup - force = resource.Body("force", type=bool) - #: backup name - name = resource.Body("name") - #: backup description - description = resource.Body("description") - #: backup status - #: values: creating, available, deleting, error, restoring, error_restoring - status = resource.Body("status") - #: backup availability zone - availability_zone = resource.Body("availability_zone") - #: backup size - size = resource.Body("size", type=int) - #: backup object count - object_count = resource.Body("object_count", type=int) - #: Backup fail reason - fail_reason = resource.Body("fail_reason") - #: The container backup in - container = resource.Body("container") - #: The container created at - created_at = resource.Body("created_at") - #: The container updated at - updated_at = resource.Body("updated_at") - #: has_dependent_backups - #: If this value is true, there are other backups depending on this backup. - has_dependent_backups = resource.Body('has_dependent_backups', type=bool) - #: data timestamp - #: The time when the data on the volume was first saved. - #: If it is a backup from volume, it will be the same as created_at - #: for a backup. If it is a backup from a snapshot, - #: it will be the same as created_at for the snapshot. - data_timestamp = resource.Body('data_timestamp') - #: OTC extensions - #: The tenant which backup belongs to - tenant_id = resource.Body("os-bak-tenant-attr:tenant_id") - #: Backup metadata - service_metadata = resource.Body("service_metadata") - - @classmethod - def list(cls, session, paginated=False, details=False, - endpoint_override=None, headers=None, **params): - - if not cls.allow_list: - raise exceptions.MethodNotSupported(cls, "list") - - session = cls._get_session(session) - - cls._query_mapping._validate(params, base_path=cls.base_path) - query_params = cls._query_mapping._transpose(params) - # Check, which uri should we go to - uri = (cls.base_path if not details else cls.details_list_path) \ - % params - - limit = query_params.get('limit') - - # Build additional arguments to the GET call - get_args = cls._prepare_override_args( - endpoint_override=endpoint_override, - # request_headers=request.headers, - additional_headers=headers) - - total_yielded = 0 - while uri: - response = session.get( - uri, - params=query_params.copy(), - **get_args - ) - exceptions.raise_from_response(response) - data = response.json() - - # Discard any existing pagination keys - query_params.pop('marker', None) - query_params.pop('limit', None) - - if cls.resources_key: - resources = data[cls.resources_key] - else: - resources = data - - if not isinstance(resources, list): - resources = [resources] - - marker = None - for raw_resource in resources: - # Do not allow keys called "self" through. Glance chose - # to name a key "self", so we need to pop it out because - # we can't send it through cls.existing and into the - # Resource initializer. "self" is already the first - # argument and is practically a reserved word. - raw_resource.pop("self", None) - - if cls.resource_key and cls.resource_key in raw_resource: - raw_resource = raw_resource[cls.resource_key] - - value = cls.existing(**raw_resource) - - marker = value.id - yield value - total_yielded += 1 - - if resources and paginated: - uri, next_params = cls._get_next_link( - uri, response, data, marker, limit, total_yielded) - query_params.update(next_params) - else: - return - - def restore(self, session, volume_id): - """Restore current backup to volume - - :param session: openstack session - :param volume_id: the volume be restored - :return: - """ - url = utils.urljoin(self.base_path, self.id, "restore") - body = {"restore": {"volume_id": volume_id}} - response = session.post(url, - json=body) - self._translate_response(response) - return self diff --git a/otcextensions/sdk/volume_backup/v2/backup_policy.py b/otcextensions/sdk/volume_backup/v2/backup_policy.py index f6b2e37f3..597e91de8 100644 --- a/otcextensions/sdk/volume_backup/v2/backup_policy.py +++ b/otcextensions/sdk/volume_backup/v2/backup_policy.py @@ -12,10 +12,8 @@ from openstack import resource from openstack import utils -from otcextensions.sdk import sdk_resource - -class SchedulePolicy(sdk_resource.Resource): +class SchedulePolicy(resource.Resource): #: whether keep the first backup of current month remain_first_backup_of_curMonth = resource.Body( "remain_first_backup_of_curMonth") @@ -29,7 +27,7 @@ class SchedulePolicy(sdk_resource.Resource): status = resource.Body("status") -class BackupPolicy(sdk_resource.Resource): +class BackupPolicy(resource.Resource): """Volume BackupPolicy""" resources_key = "backup_policies" base_path = "/backuppolicy" @@ -38,7 +36,7 @@ class BackupPolicy(sdk_resource.Resource): allow_create = True allow_delete = True allow_list = True - allow_update = True + allow_commit = True # allow_get = True #: Properties @@ -63,7 +61,7 @@ def execute(self, session): return session.post(url, json=None) -class BackupPolicyAssociatedResource(sdk_resource.Resource): +class BackupPolicyAssociatedResource(resource.Resource): #: Properties resource_id = resource.Body("resource_id") resource_type = resource.Body("resource_type") @@ -73,7 +71,7 @@ class BackupPolicyAssociatedResource(sdk_resource.Resource): code = resource.Body("code") -class BackupPolicyResource(sdk_resource.Resource): +class BackupPolicyResource(resource.Resource): base_path = "/backuppolicyresources" # capabilities diff --git a/otcextensions/sdk/volume_backup/volume_backup_service.py b/otcextensions/sdk/volume_backup/volume_backup_service.py index 01ba87198..5c79044ee 100644 --- a/otcextensions/sdk/volume_backup/volume_backup_service.py +++ b/otcextensions/sdk/volume_backup/volume_backup_service.py @@ -11,7 +11,7 @@ # under the License. from openstack import service_description -from otcextensions.sdk.volume_backup.v1 import _proxy +from otcextensions.sdk.volume_backup.v2 import _proxy class VolumeBackupService(service_description.ServiceDescription): diff --git a/otcextensions/tests/functional/sdk/test_openstacksdk_init.py b/otcextensions/tests/functional/sdk/test_openstacksdk_init.py new file mode 100644 index 000000000..f2c494370 --- /dev/null +++ b/otcextensions/tests/functional/sdk/test_openstacksdk_init.py @@ -0,0 +1,27 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# 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 openstack + +from otcextensions.tests.functional import base + + +class TestOtcextensionsInitialization(base.BaseFunctionalTest): + + def test_basic(self): + conn = openstack.connect( + vendor_hook='otcextensions.sdk:load' + ) + + self.assertTrue(hasattr(conn.dns, 'add_router_to_zone')) + list(conn.volume_backup.backup_policies()) + list(conn.obs.containers()) diff --git a/otcextensions/tests/unit/osclient/auto_scaling/v1/test_group.py b/otcextensions/tests/unit/osclient/auto_scaling/v1/test_group.py index ab93c2280..6c98e5011 100644 --- a/otcextensions/tests/unit/osclient/auto_scaling/v1/test_group.py +++ b/otcextensions/tests/unit/osclient/auto_scaling/v1/test_group.py @@ -147,9 +147,9 @@ def test_create(self): '--cool_down_time', '1', '--availability_zone', 'eu-1', '--availability_zone', 'eu-2', - '--subnetwork', 'sub1', - '--subnetwork', 'sub2', - '--network_id', 'vpc-1', + '--subnet', 'sub1', + '--subnet', 'sub2', + '--router', 'vpc-1', '--security_group', 'sg1', '--security_group', 'sg2', '--lb_listener_id', 'lb1', @@ -169,9 +169,9 @@ def test_create(self): ('max_instance_number', 15), ('cool_down_time', 1), ('availability_zone', ['eu-1', 'eu-2']), - ('subnetwork', ['sub1', 'sub2']), + ('subnet', ['sub1', 'sub2']), ('security_group', ['sg1', 'sg2']), - ('network_id', 'vpc-1'), + ('router', 'vpc-1'), ('lb_listener_id', 'lb1'), ('lbaas_listener', ['lbas1:14', 'lbas2:15:10']), ('audit_method', 'some_method'), diff --git a/otcextensions/tests/unit/osclient/dms/v1/test_group.py b/otcextensions/tests/unit/osclient/dms/v1/test_group.py index a65ad16e8..2539188b8 100644 --- a/otcextensions/tests/unit/osclient/dms/v1/test_group.py +++ b/otcextensions/tests/unit/osclient/dms/v1/test_group.py @@ -27,6 +27,7 @@ def setUp(self): class TestListGroup(TestGroup): groups = fakes.FakeGroup.create_multiple(3) + queue = fakes.FakeQueue.create_one() columns = ('ID', 'name', 'produced_messages', 'consumed_messages', 'available_messages') @@ -61,6 +62,7 @@ def setUp(self): self.cmd = group.ListGroup(self.app, None) self.client.groups = mock.Mock() + self.client.find_queue = mock.Mock() def test_list_group(self): arglist = [ @@ -78,12 +80,15 @@ def test_list_group(self): self.client.groups.side_effect = [ self.groups ] + self.client.find_queue.side_effect = [ + self.queue + ] # Trigger the action columns, data = self.cmd.take_action(parsed_args) self.client.groups.assert_called_once_with( - queue='queue_id', + queue=self.queue.id, include_deadletter=False) self.assertEqual(self.columns, columns) @@ -107,12 +112,15 @@ def test_list_group_ext(self): self.client.groups.side_effect = [ self.groups ] + self.client.find_queue.side_effect = [ + self.queue + ] # Trigger the action columns, data = self.cmd.take_action(parsed_args) self.client.groups.assert_called_once_with( - queue='queue_id', + queue=self.queue.id, include_deadletter=True) self.assertEqual(self.columns_with_dead, columns) diff --git a/otcextensions/tests/unit/sdk/anti_ddos/v1/test_floating_ip.py b/otcextensions/tests/unit/sdk/anti_ddos/v1/test_floating_ip.py index f8a64b7e4..da1854e3f 100644 --- a/otcextensions/tests/unit/sdk/anti_ddos/v1/test_floating_ip.py +++ b/otcextensions/tests/unit/sdk/anti_ddos/v1/test_floating_ip.py @@ -41,9 +41,9 @@ def test_basic(self): self.assertEqual('ddosStatus', sot.resources_key) self.assertTrue(sot.allow_list) - self.assertTrue(sot.allow_get) + self.assertTrue(sot.allow_fetch) self.assertTrue(sot.allow_delete) - self.assertTrue(sot.allow_update) + self.assertTrue(sot.allow_commit) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/anti_ddos/v1/test_proxy.py b/otcextensions/tests/unit/sdk/anti_ddos/v1/test_proxy.py index 98c0c9fc0..566f10e46 100644 --- a/otcextensions/tests/unit/sdk/anti_ddos/v1/test_proxy.py +++ b/otcextensions/tests/unit/sdk/anti_ddos/v1/test_proxy.py @@ -28,39 +28,33 @@ def setUp(self): def test_floating_ips(self): self.verify_list( self.proxy.floating_ips, _floating_ip.FloatingIP, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', expected_kwargs={'paginated': False} ) def test_unprotect_floating_ip(self): self.verify_delete( self.proxy.unprotect_floating_ip, _floating_ip.FloatingIP, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', ) def test_get_floating_ip_policies(self): self.verify_get( self.proxy.get_floating_ip_policies, _floating_ip.FloatingIP, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', ) def test_update_floating_ip_policies(self): self.verify_update( self.proxy.update_floating_ip_policies, _floating_ip.FloatingIP, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._update', ) def test_configs(self): self.verify_list( self.proxy.configs, _config.Config, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', expected_kwargs={'paginated': False} ) def test_get_floating_ip_status(self): self.verify_get( self.proxy.get_floating_ip_status, _status.FloatingIPStatus, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', expected_kwargs={ 'requires_id': False, } @@ -69,7 +63,6 @@ def test_get_floating_ip_status(self): def test_float_ip_logs(self): self.verify_list( self.proxy.floating_ip_events, _status.FloatingIPEvent, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'floating_ip_id': 'ip_id' }, @@ -82,7 +75,6 @@ def test_float_ip_logs(self): def test_float_ip_stat_day(self): self.verify_list( self.proxy.floating_ip_stat_day, _status.FloatingIPDayStat, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'floating_ip_id': 'ip_id' }, @@ -94,7 +86,7 @@ def test_float_ip_stat_day(self): def test_float_ip_stat_week(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._get', + 'openstack.proxy.Proxy._get', self.proxy.floating_ip_stat_week, method_args=None, method_kwargs={ diff --git a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_activity.py b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_activity.py index ec594358d..7a8ef2be7 100644 --- a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_activity.py +++ b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_activity.py @@ -9,8 +9,6 @@ # 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 copy - from keystoneauth1 import adapter import mock @@ -60,7 +58,9 @@ class TestActivity(base.TestCase): def setUp(self): super(TestActivity, self).setUp() self.sess = mock.Mock(spec=adapter.Adapter) + self.sess.default_microversion = None self.sess.get = mock.Mock() + self.sess._get_connection = mock.Mock(return_value=self.cloud) self.sot = activity.Activity() @@ -72,8 +72,8 @@ def test_basic(self): sot.base_path) self.assertTrue(sot.allow_list) self.assertFalse(sot.allow_create) - self.assertFalse(sot.allow_get) - self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_commit) + self.assertFalse(sot.allow_commit) self.assertFalse(sot.allow_delete) def test_make_it(self): @@ -93,40 +93,3 @@ def test_make_it(self): self.assertEqual(obj['instance_deleted_list'], sot.instance_deleted_list) self.assertEqual(obj['description'], sot.description) - - def test_list(self): - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.json.return_value = copy.deepcopy(EXAMPLE_LIST) - - self.sess.get.return_value = mock_response - - result = list( - self.sot.list( - self.sess, - scaling_group_id='grp_id', - limit=3, - marker=4, - start_time='a', - end_time='b' - ) - ) - - self.sess.get.assert_called_once_with( - '/scaling_activity_log/grp_id', - params={ - 'limit': 3, - 'start_number': 4, - 'start_time': 'a', - 'end_time': 'b' - }, - ) - - expected_list = [ - activity.Activity.existing( - **EXAMPLE_LIST['scaling_activity_log'][0]), - activity.Activity.existing( - **EXAMPLE_LIST['scaling_activity_log'][1]), - ] - - self.assertEqual(expected_list, result) diff --git a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_config.py b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_config.py index af0def842..478af64e6 100644 --- a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_config.py +++ b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_config.py @@ -9,8 +9,6 @@ # 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 copy - from keystoneauth1 import adapter import mock @@ -136,7 +134,7 @@ def test_basic(self): self.assertTrue(sot.allow_list) self.assertTrue(sot.allow_create) self.assertTrue(sot.allow_get) - self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_commit) self.assertTrue(sot.allow_delete) def test_make_it(self): @@ -144,48 +142,3 @@ def test_make_it(self): self.assertEqual(EXAMPLE['scaling_configuration_id'], sot.id) self.assertEqual(EXAMPLE['scaling_configuration_name'], sot.name) self.assertEqual(EXAMPLE['create_time'], sot.create_time) - - def test_list(self): - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.json.return_value = copy.deepcopy(EXAMPLE_LIST) - - self.sess.get.return_value = mock_response - - result = list(self.sot.list(self.sess)) - - self.sess.get.assert_called_once_with( - '/scaling_configuration', - params={}, - ) - - expected_list = [ - config.Config.existing( - **EXAMPLE_LIST['scaling_configurations'][0]), - config.Config.existing( - **EXAMPLE_LIST['scaling_configurations'][1]) - ] - - self.assertEqual(expected_list, result) - - def test_get(self): - sot = config.Config.existing( - id=EXAMPLE['scaling_configuration_id']) - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = { - 'scaling_configuration': EXAMPLE.copy()} - - self.sess.get.return_value = mock_response - - result = sot.get(self.sess) - - self.sess.get.assert_called_once_with( - 'scaling_configuration/%s' % - EXAMPLE['scaling_configuration_id'], - ) - - self.assertEqual(sot, result) - self.assertEqual(EXAMPLE['scaling_configuration_id'], result.id) - self.assertEqual(EXAMPLE['scaling_configuration_name'], result.name) diff --git a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_group.py b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_group.py index cd27b687c..e825cc740 100644 --- a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_group.py +++ b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_group.py @@ -9,8 +9,6 @@ # 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 copy - from keystoneauth1 import adapter import mock @@ -83,39 +81,3 @@ def test_make_it(self): self.assertEqual(EXAMPLE['scaling_group_id'], sot.id) self.assertEqual(EXAMPLE['scaling_group_name'], sot.name) self.assertEqual(EXAMPLE['create_time'], sot.create_time) - - def test_list(self): - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.json.return_value = {'scaling_groups': [EXAMPLE]} - - self.sess.get.return_value = mock_response - - result = list(self.sot.list(self.sess)) - - self.sess.get.assert_called_once_with( - '/scaling_group', - params={}, - ) - - self.assertEqual([group.Group(**EXAMPLE)], result) - - def test_get(self): - sot = group.Group.existing( - id=EXAMPLE['scaling_group_id']) - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = copy.deepcopy(EXAMPLE) - - self.sess.get.return_value = mock_response - - result = sot.get(self.sess) - - self.sess.get.assert_called_once_with( - 'scaling_group/%s' % EXAMPLE['scaling_group_id'], - ) - - self.assertEqual(sot, result) - self.assertEqual(EXAMPLE['scaling_group_id'], result.id) - self.assertEqual(EXAMPLE['scaling_group_name'], result.name) diff --git a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_instance.py b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_instance.py index 3d682f419..53aaba8a4 100644 --- a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_instance.py +++ b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_instance.py @@ -77,8 +77,8 @@ def test_basic(self): '/scaling_group_instance/%(scaling_group_id)s/list', sot.list_path) self.assertTrue(sot.allow_list) self.assertFalse(sot.allow_create) - self.assertFalse(sot.allow_get) - self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_fetch) + self.assertFalse(sot.allow_commit) self.assertTrue(sot.allow_delete) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_policy.py b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_policy.py index 2198831d1..ce356f039 100644 --- a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_policy.py +++ b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_policy.py @@ -66,10 +66,12 @@ class TestPolicy(base.TestCase): def setUp(self): super(TestPolicy, self).setUp() self.sess = mock.Mock(spec=adapter.Adapter) + self.sess.default_microversion = None self.sess.get = mock.Mock() self.sess.post = mock.Mock() self.sess.delete = mock.Mock() self.sess.put = mock.Mock() + self.sess.retriable_status_codes = () # self.sess.get_project_id = mock.Mock(return_value=PROJECT_ID) self.sot = policy.Policy() @@ -82,8 +84,8 @@ def test_basic(self): '/scaling_policy/%(scaling_group_id)s/list', sot.list_path) self.assertTrue(sot.allow_list) self.assertTrue(sot.allow_create) - self.assertTrue(sot.allow_get) - self.assertTrue(sot.allow_update) + self.assertTrue(sot.allow_fetch) + self.assertTrue(sot.allow_commit) self.assertTrue(sot.allow_delete) def test_make_it(self): @@ -138,11 +140,12 @@ def test_get(self): self.sess.get.return_value = mock_response - result = sot.get(self.sess) + result = sot.fetch(self.sess) self.sess.get.assert_called_once_with( 'scaling_policy/%s' % EXAMPLE['scaling_policy_id'], + microversion=None ) self.assertEqual(sot, result) @@ -207,7 +210,7 @@ def test_update(self): sot._update(**EXAMPLE) - result = sot.update(self.sess, prepend_key=False) + result = sot.commit(self.sess, prepend_key=False) call_args = self.sess.put.call_args_list[0] diff --git a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_proxy.py b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_proxy.py index 74aa2714f..e945f24cc 100644 --- a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_proxy.py +++ b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_proxy.py @@ -31,7 +31,6 @@ class TestAutoScalingGroups(TestAutoScalingProxy): def test_list(self): self.verify_list( self.proxy.groups, _group.Group, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'some_arg': 'arg_value', }, @@ -44,14 +43,13 @@ def test_get(self): self.verify_get( self.proxy.get_group, _group.Group, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', expected_kwargs={ } ) def test_find(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._find', + 'openstack.proxy.Proxy._find', self.proxy.find_group, method_args=["flavor"], expected_args=[_group.Group, "flavor"], @@ -61,7 +59,6 @@ def test_find(self): def test_create(self): self.verify_create( self.proxy.create_group, _group.Group, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', method_kwargs={ 'instance': 'test', 'name': 'some_name' @@ -77,14 +74,13 @@ def test_delete(self): self.verify_delete( self.proxy.delete_group, _group.Group, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', expected_kwargs={ } ) def test_update(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._update', + 'openstack.proxy.Proxy._update', self.proxy.update_group, method_args=['INSTANCE'], method_kwargs={'test': 't'}, @@ -101,7 +97,6 @@ class TestAutoScalingConfigs(TestAutoScalingProxy): def test_list(self): self.verify_list( self.proxy.configs, _config.Config, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'some_arg': 'arg_value', }, @@ -114,14 +109,13 @@ def test_get(self): self.verify_get( self.proxy.get_config, _config.Config, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', expected_kwargs={ } ) def test_find(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._find', + 'openstack.proxy.Proxy._find', self.proxy.find_config, method_args=["flavor"], expected_args=[_config.Config, "flavor"], @@ -131,7 +125,6 @@ def test_find(self): def test_create(self): self.verify_create( self.proxy.create_config, _config.Config, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', method_kwargs={ 'instance_config': {}, 'name': 'some_name' @@ -147,7 +140,6 @@ def test_delete(self): self.verify_delete( self.proxy.delete_config, _config.Config, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', expected_kwargs={ } ) @@ -158,7 +150,6 @@ class TestAutoScalingPolicy(TestAutoScalingProxy): def test_list(self): self.verify_list( self.proxy.policies, _policy.Policy, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'some_arg': 'arg_value', 'group': 'group_id' @@ -173,7 +164,6 @@ def test_delete(self): self.verify_delete( self.proxy.delete_policy, _policy.Policy, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', expected_kwargs={ } ) @@ -181,7 +171,6 @@ def test_delete(self): def test_create(self): self.verify_create( self.proxy.create_policy, _policy.Policy, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', method_kwargs={ 'name': 'some_name' }, @@ -193,7 +182,7 @@ def test_create(self): def test_find(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._find', + 'openstack.proxy.Proxy._find', self.proxy.find_policy, method_args=['pol'], expected_args=[_policy.Policy, 'pol'], @@ -202,7 +191,7 @@ def test_find(self): def test_update(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._update', + 'openstack.proxy.Proxy._update', self.proxy.update_policy, method_args=['INSTANCE'], method_kwargs={'test': 't'}, @@ -243,7 +232,6 @@ class TestAutoScalingActivityLog(TestAutoScalingProxy): def test_list(self): self.verify_list( self.proxy.activities, _activity.Activity, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'some_arg': 'arg_value', 'group': 'group_id' @@ -260,7 +248,6 @@ class TestAutoScalingQuota(TestAutoScalingProxy): def test_list(self): self.verify_list( self.proxy.quotas, _quota.Quota, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', expected_kwargs={ 'paginated': False } @@ -269,7 +256,6 @@ def test_list(self): def test_list_scaling(self): self.verify_list( self.proxy.quotas, _quota.ScalingQuota, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_args=['INSTANCE'], expected_kwargs={ 'paginated': False, @@ -283,7 +269,6 @@ class TestAutoScalingInstance(TestAutoScalingProxy): def test_list(self): self.verify_list( self.proxy.instances, _instance.Instance, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_args=['group'], expected_kwargs={ 'scaling_group_id': 'group' diff --git a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_quota.py b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_quota.py index f63f9f164..f50ca9d5e 100644 --- a/otcextensions/tests/unit/sdk/auto_scaling/v1/test_quota.py +++ b/otcextensions/tests/unit/sdk/auto_scaling/v1/test_quota.py @@ -67,8 +67,8 @@ def test_basic(self): self.assertEqual('/quotas', sot.base_path) self.assertTrue(sot.allow_list) self.assertFalse(sot.allow_create) - self.assertFalse(sot.allow_get) - self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_fetch) + self.assertFalse(sot.allow_commit) self.assertFalse(sot.allow_delete) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/cts/v1/test_proxy.py b/otcextensions/tests/unit/sdk/cts/v1/test_proxy.py index 1cfad2348..c008170cf 100644 --- a/otcextensions/tests/unit/sdk/cts/v1/test_proxy.py +++ b/otcextensions/tests/unit/sdk/cts/v1/test_proxy.py @@ -26,7 +26,6 @@ def setUp(self): def test_traces(self): self.verify_list( self.proxy.traces, _trace.Trace, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', expected_kwargs={ 'limit': 50, 'tracker_name': 'system' @@ -36,7 +35,6 @@ def test_traces(self): def test_traces_query(self): self.verify_list( self.proxy.traces, _trace.Trace, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'next': '1', 'limit': '2', @@ -71,7 +69,6 @@ def test_traces_query(self): def test_get_tracker(self): self.verify_get( self.proxy.get_tracker, _tracker.Tracker, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', expected_args=[_tracker.Tracker, 'value'], expected_kwargs={ 'requires_id': False @@ -81,17 +78,14 @@ def test_get_tracker(self): def test_create_tracker(self): self.verify_create( self.proxy.create_tracker, _tracker.Tracker, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', ) def test_update_tracker(self): self.verify_update( self.proxy.update_tracker, _tracker.Tracker, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._update', ) def test_delete_tracker(self): self.verify_delete( self.proxy.delete_tracker, _tracker.Tracker, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', ) diff --git a/otcextensions/tests/unit/sdk/cts/v1/test_tracker.py b/otcextensions/tests/unit/sdk/cts/v1/test_tracker.py index 1550745fc..365e463bb 100644 --- a/otcextensions/tests/unit/sdk/cts/v1/test_tracker.py +++ b/otcextensions/tests/unit/sdk/cts/v1/test_tracker.py @@ -37,10 +37,10 @@ def test_basic(self): self.assertEqual('/tracker', sot.base_path) - self.assertTrue(sot.allow_get) + self.assertTrue(sot.allow_fetch) self.assertTrue(sot.allow_create) self.assertTrue(sot.allow_delete) - self.assertTrue(sot.allow_update) + self.assertTrue(sot.allow_commit) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/dcs/v1/test_config.py b/otcextensions/tests/unit/sdk/dcs/v1/test_config.py index cd5bd1bcc..c7999be60 100644 --- a/otcextensions/tests/unit/sdk/dcs/v1/test_config.py +++ b/otcextensions/tests/unit/sdk/dcs/v1/test_config.py @@ -42,7 +42,7 @@ def test_basic(self): self.assertEqual('/instances/%(instance_id)s/configs', sot.base_path) - self.assertTrue(sot.allow_update) + self.assertTrue(sot.allow_commit) self.assertTrue(sot.allow_list) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/dcs/v1/test_instance.py b/otcextensions/tests/unit/sdk/dcs/v1/test_instance.py index 7a598463a..a06d7e40d 100644 --- a/otcextensions/tests/unit/sdk/dcs/v1/test_instance.py +++ b/otcextensions/tests/unit/sdk/dcs/v1/test_instance.py @@ -65,8 +65,8 @@ def test_basic(self): self.assertTrue(sot.allow_create) self.assertTrue(sot.allow_list) - self.assertTrue(sot.allow_get) - self.assertTrue(sot.allow_update) + self.assertTrue(sot.allow_fetch) + self.assertTrue(sot.allow_commit) self.assertTrue(sot.allow_delete) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py b/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py index 6eb8a8d1e..99b810e88 100644 --- a/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py +++ b/otcextensions/tests/unit/sdk/dcs/v1/test_proxy.py @@ -30,19 +30,16 @@ def setUp(self): def test_create_instance(self): self.verify_create( self.proxy.create_instance, _instance.Instance, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', ) def test_instances(self): self.verify_list( self.proxy.instances, _instance.Instance, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', ) def test_instances_query(self): self.verify_list( self.proxy.instances, _instance.Instance, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_kwargs={ 'start': '1', 'limit': '2', @@ -64,13 +61,11 @@ def test_instances_query(self): def test_get_instance(self): self.verify_get( self.proxy.get_instance, _instance.Instance, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', ) def test_find_instance(self): self.verify_find( self.proxy.find_instance, _instance.Instance, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._find', ) def test_update_instance(self): @@ -117,7 +112,6 @@ def test_extend_instance(self): def test_delete_instance(self): self.verify_delete( self.proxy.delete_instance, _instance.Instance, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', ) def test_stop_instance(self): @@ -186,7 +180,6 @@ def test_change_pwd(self): def test_statistics(self): self.verify_list( self.proxy.statistics, _stat.Statistic, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', expected_kwargs={ 'paginated': False } @@ -241,7 +234,6 @@ def test_create_backup(self): def test_delete_backup(self): self.verify_delete( self.proxy.delete_instance_backup, _backup.Backup, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', ) def test_restores_query(self): diff --git a/otcextensions/tests/unit/sdk/deh/v1/test_host.py b/otcextensions/tests/unit/sdk/deh/v1/test_host.py index 6be3603e7..298996c23 100644 --- a/otcextensions/tests/unit/sdk/deh/v1/test_host.py +++ b/otcextensions/tests/unit/sdk/deh/v1/test_host.py @@ -64,10 +64,10 @@ def test_basic(self): self.assertEqual('/dedicated-hosts', sot.base_path) self.assertTrue(sot.allow_list) - self.assertTrue(sot.allow_get) + self.assertTrue(sot.allow_fetch) self.assertTrue(sot.allow_create) self.assertTrue(sot.allow_delete) - self.assertTrue(sot.allow_update) + self.assertTrue(sot.allow_commit) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/deh/v1/test_host_type.py b/otcextensions/tests/unit/sdk/deh/v1/test_host_type.py index e8dc1bb1d..121e48cf6 100644 --- a/otcextensions/tests/unit/sdk/deh/v1/test_host_type.py +++ b/otcextensions/tests/unit/sdk/deh/v1/test_host_type.py @@ -31,10 +31,10 @@ def test_basic(self): sot.base_path) self.assertTrue(sot.allow_list) - self.assertFalse(sot.allow_get) + self.assertFalse(sot.allow_fetch) self.assertFalse(sot.allow_create) self.assertFalse(sot.allow_delete) - self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_commit) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/deh/v1/test_proxy.py b/otcextensions/tests/unit/sdk/deh/v1/test_proxy.py index 7465c7123..2ce691509 100644 --- a/otcextensions/tests/unit/sdk/deh/v1/test_proxy.py +++ b/otcextensions/tests/unit/sdk/deh/v1/test_proxy.py @@ -26,7 +26,6 @@ def setUp(self): def test_hosts(self): self.verify_list( self.proxy.hosts, _host.Host, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', expected_kwargs={ } ) @@ -34,19 +33,16 @@ def test_hosts(self): def test_get_host(self): self.verify_get( self.proxy.get_host, _host.Host, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', ) def test_find_host(self): self.verify_find( self.proxy.find_host, _host.Host, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._find', ) def test_create_host(self): self.verify_create( self.proxy.create_host, _host.Host, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', method_kwargs={ 'x': 1, 'y': '2' @@ -61,19 +57,16 @@ def test_create_host(self): def test_delete_host(self): self.verify_delete( self.proxy.delete_host, _host.Host, ignore=True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', ) def test_update_host(self): self.verify_update( self.proxy.update_host, _host.Host, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._update', ) def test_servers(self): self.verify_list( self.proxy.servers, _server.Server, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_args=[{'id': 'host_id'}], method_kwargs={}, expected_kwargs={ @@ -84,7 +77,6 @@ def test_servers(self): def test_host_types(self): self.verify_list( self.proxy.host_types, _host_type.HostType, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', method_args=['az'], method_kwargs={}, expected_kwargs={ diff --git a/otcextensions/tests/unit/sdk/deh/v1/test_server.py b/otcextensions/tests/unit/sdk/deh/v1/test_server.py index b2c516589..a3e8dbb32 100644 --- a/otcextensions/tests/unit/sdk/deh/v1/test_server.py +++ b/otcextensions/tests/unit/sdk/deh/v1/test_server.py @@ -49,10 +49,10 @@ def test_basic(self): sot.base_path) self.assertTrue(sot.allow_list) - self.assertFalse(sot.allow_get) + self.assertFalse(sot.allow_fetch) self.assertFalse(sot.allow_create) self.assertFalse(sot.allow_delete) - self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_commit) def test_make_it(self): diff --git a/otcextensions/tests/unit/sdk/volume_backup/v2/test_backup.py b/otcextensions/tests/unit/sdk/volume_backup/v2/test_backup.py deleted file mode 100644 index f008292d2..000000000 --- a/otcextensions/tests/unit/sdk/volume_backup/v2/test_backup.py +++ /dev/null @@ -1,222 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the 'License'); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT -# 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 copy -import json -import os - -from keystoneauth1 import adapter - -import mock - -from openstack.tests.unit import base - -from otcextensions.sdk.volume_backup.v2 import backup as _backup - -TESTDATA_DIR = os.path.join(os.path.dirname(__file__)) - - -def _get_fixture(name): - fixture = os.path.join( - TESTDATA_DIR, - 'data_files/', - name) - with open(fixture, 'r') as data: - return json.load(data) - - -class TestBackup(base.TestCase): - - def setUp(self): - super(TestBackup, self).setUp() - self.sess = mock.Mock(spec=adapter.Adapter) - self.sess.get = mock.Mock() - self.sess.post = mock.Mock() - self.sess.put = mock.Mock() - self.sess.delete = mock.Mock() - - self.get_backup_data = _get_fixture('get_backup.json') - self.list_backup_data = _get_fixture('list_backups.json') - - obj = self.get_backup_data['backup'] - self.sot = _backup.Backup.existing(**obj) - - def test_basic(self): - sot = _backup.Backup() - self.assertEqual('backup', sot.resource_key) - self.assertEqual('backups', sot.resources_key) - self.assertEqual('/backups', - sot.base_path) - self.assertTrue(sot.allow_list) - self.assertTrue(sot.allow_create) - self.assertTrue(sot.allow_get) - self.assertTrue(sot.allow_delete) - self.assertFalse(sot.allow_update) - - def test_make_it(self): - obj = self.get_backup_data['backup'] - sot = self.sot - self.assertEqual(obj['id'], sot.id) - self.assertEqual(obj['volume_id'], sot.volume_id) - self.assertEqual(obj['status'], sot.status) - self.assertEqual(obj['description'], sot.description) - self.assertEqual(obj['availability_zone'], sot.availability_zone) - self.assertEqual(obj['size'], sot.size) - self.assertEqual(obj['container'], sot.container) - self.assertEqual(obj['created_at'], sot.created_at) - - def mocked_requests_list(*args, **kwargs): - - class MockResponse(object): - def __init__(self, json_data, status_code): - self.json_data = copy.deepcopy(json_data) - self.status_code = status_code - - def json(self): - return self.json_data - - if args[1] == '/backups': - response = _get_fixture('list_backups.json') - return MockResponse(response, 200) - elif args[1] == '/backups/detail': - response = _get_fixture('list_backup_details.json') - return MockResponse(response, 200) - - return MockResponse({'backups': []}, 200) - - def test_list(self): - """Test list together with pagination - """ - - self.sess.get.side_effect = self.mocked_requests_list - - result = list(self.sot.list( - self.sess, - # paginated=True, - # name='test_name', - # status='test_status', - # offset=4, - # limit=1, - # volume_id='vol_id' - )) - - calls = [ - mock.call( - '/backups', - params={ - # 'name': 'test_name', - # 'status': 'test_status', - # 'volume_id': 'vol_id' - }), - # mock.call( - # self.list_backup_data['backups_links'][0]['href'], - # params={ - # # 'name': 'test_name', - # # 'status': 'test_status', - # # 'volume_id': 'vol_id' - # }), - ] - - self.sess.get.assert_has_calls(calls) - - self.assertEqual(len(self.list_backup_data), len(result)) - - def test_get(self): - data = self.get_backup_data['backup'] - sot = _backup.Backup.existing(id=data['id']) - - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = copy.deepcopy(self.get_backup_data) - - self.sess.get.return_value = mock_response - - result = sot.get(self.sess) - - self.sess.get.assert_called_once_with( - 'backups/%s' % data['id'], - ) - - self.assertDictEqual( - _backup.Backup.existing(**data).to_dict(), - result.to_dict()) - - def test_create(self): - data = _get_fixture('create_native_backup_response.json')['backup'] - backup = { - 'volume_id': 'vol_id', - 'snapshot_id': 'snap', - 'name': data['name'], - 'description': 'descr' - } - sot = _backup.Backup.new(**backup) - - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = copy.deepcopy(data) - - self.sess.post.return_value = mock_response - - result = sot.create(self.sess, prepend_key=True) - - call_args = self.sess.post.call_args_list[0] - - expected_json = {'backup': copy.deepcopy(backup)} - - self.assertEqual('/backups', call_args[0][0]) - self.assertDictEqual(expected_json, call_args[1]['json']) - - self.sess.post.assert_called_once() - - self.assertEqual(result.name, data['name']) - self.assertEqual(result.id, data['id']) - - def test_delete(self): - data = self.get_backup_data['backup'] - sot = _backup.Backup.existing(id=data['id']) - - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = {} - - self.sess.delete.return_value = mock_response - - sot.delete(self.sess) - - self.sess.delete.assert_called_once_with( - 'backups/%s' % data['id'], - ) - - def test_restore(self): - sot = _backup.Backup.existing(id='some_id') - - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = { - "restore": { - "backup_id": "2ef47aee-8844-490c-804d-2a8efe561c65", - "volume_id": "795114e8-7489-40be-a978-83797f2c1dd3", - "volume_name": "volume01" - } - } - - self.sess.post.return_value = mock_response - - sot.restore(self.sess, volume_id='vol_id') - - self.sess.post.assert_called_once_with( - 'backups/%s/restore' % 'some_id', - json={'restore': {'volume_id': 'vol_id'}} - ) diff --git a/otcextensions/tests/unit/sdk/volume_backup/v2/test_backup_policy.py b/otcextensions/tests/unit/sdk/volume_backup/v2/test_backup_policy.py index 821e75d41..dd90a853b 100644 --- a/otcextensions/tests/unit/sdk/volume_backup/v2/test_backup_policy.py +++ b/otcextensions/tests/unit/sdk/volume_backup/v2/test_backup_policy.py @@ -9,7 +9,6 @@ # 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 copy import json import os @@ -64,9 +63,9 @@ def test_basic(self): self.assertEqual('/backuppolicy', sot.base_path) self.assertTrue(sot.allow_list) self.assertTrue(sot.allow_create) - self.assertFalse(sot.allow_get) + self.assertFalse(sot.allow_fetch) self.assertTrue(sot.allow_delete) - self.assertTrue(sot.allow_update) + self.assertTrue(sot.allow_commit) def test_make_it(self): sot = _backup_policy.BackupPolicy.existing(**EXAMPLE) @@ -94,160 +93,6 @@ def test_make_it(self): sp_compare['start_time'], sp.start_time) - def test_list(self): - response = _get_fixture('list_backup_policies.json') - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.json.return_value = copy.deepcopy(response) - - self.sess.get.return_value = mock_response - - result = list(self.sot.list(self.sess)) - - self.sess.get.assert_called_once_with( - '/backuppolicy', - params={} - ) - - self.assertIsNotNone(result) - - for bp in result: - assert isinstance(bp, _backup_policy.BackupPolicy) - - def test_create(self): - sot = _backup_policy.BackupPolicy.new(**EXAMPLE) - - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = {'backup_policy_id': 'some_id'} - - self.sess.post.return_value = mock_response - - result = sot.create(self.sess, prepend_key=True) - - call_args = self.sess.post.call_args_list[0] - - expected_json = { - 'backup_policy_id': 'XX', - 'policy_resource_count': 0, - 'scheduled_policy': { - 'remain_first_backup_of_curMonth': 'N', - 'rentention_num': 10, - 'frequency': 1, - 'start_time': '12:00', - 'status': 'ON' - }, - 'backup_policy_name': 'plan01' - } - - self.assertEqual('/backuppolicy', call_args[0][0]) - self.assertDictEqual(expected_json, call_args[1]['json']) - - self.sess.post.assert_called_once() - - self.assertEqual('some_id', result.id) - - def test_delete(self): - sot = _backup_policy.BackupPolicy.existing(id='some_id') - - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = {} - - self.sess.delete.return_value = mock_response - - sot.delete(self.sess) - - self.sess.delete.assert_called_once_with( - 'backuppolicy/%s' % 'some_id', - ) - - def test_update(self): - sot = _backup_policy.BackupPolicy.existing(id='XX') - - mock_response = mock.Mock() - mock_response.status_code = 200 - mock_response.headers = {} - mock_response.json.return_value = {'backup_policy_id': 'XX'} - - self.sess.put.return_value = mock_response - - sot._update(**EXAMPLE) - - result = sot.update(self.sess) - - call_args = self.sess.put.call_args_list[0] - - expected_json = { - 'policy_resource_count': 0, - 'scheduled_policy': { - 'remain_first_backup_of_curMonth': 'N', - 'rentention_num': 10, - 'frequency': 1, - 'start_time': '12:00', - 'status': 'ON' - }, - 'backup_policy_name': 'plan01' - } - - self.assertEqual('backuppolicy/XX', call_args[0][0]) - self.assertDictEqual(expected_json, call_args[1]['json']) - - self.sess.put.assert_called_once() - - self.assertDictEqual( - _backup_policy.BackupPolicy.existing(**EXAMPLE).to_dict(), - result.to_dict() - ) - - def mocked_requests_find(*args, **kwargs): - - class MockResponse(object): - def __init__(self, json_data, status_code): - self.json_data = copy.deepcopy(json_data) - self.status_code = status_code - self.headers = {} - - def json(self): - return self.json_data - - if args[1] == '/backuppolicy/plan02': - return MockResponse(None, 404) - elif args[1] == '/backuppolicy': - response = _get_fixture('list_backup_policies.json') - return MockResponse(response, 200) - - def test_find(self): - sot = _backup_policy.BackupPolicy() - - self.sess.get.side_effect = self.mocked_requests_find - - result = sot.find(self.sess, 'plan02') - - calls = [ - # if allow_get is False this will not be invoked - # mock.call( - # '/backuppolicy/plan02', - # params={} - # ), - mock.call( - '/backuppolicy', - params={} - ) - ] - - self.sess.get.assert_has_calls(calls) - - expected_data = \ - _get_fixture('list_backup_policies.json')['backup_policies'][1] - - self.assertDictEqual( - _backup_policy.BackupPolicy.existing(**expected_data).to_dict(), - result.to_dict() - ) - def test_execute_policy(self): sot = _backup_policy.BackupPolicy.existing(id='XX') @@ -280,9 +125,9 @@ def test_basic(self): self.assertEqual('/backuppolicyresources', sot.base_path) self.assertFalse(sot.allow_list) self.assertTrue(sot.allow_create) - self.assertFalse(sot.allow_get) + self.assertFalse(sot.allow_fetch) self.assertFalse(sot.allow_delete) - self.assertFalse(sot.allow_update) + self.assertFalse(sot.allow_commit) def test_make_it(self): sot = _backup_policy.BackupPolicyResource() diff --git a/otcextensions/tests/unit/sdk/volume_backup/v2/test_proxy.py b/otcextensions/tests/unit/sdk/volume_backup/v2/test_proxy.py index 99a0bec03..8fe96b197 100644 --- a/otcextensions/tests/unit/sdk/volume_backup/v2/test_proxy.py +++ b/otcextensions/tests/unit/sdk/volume_backup/v2/test_proxy.py @@ -13,7 +13,6 @@ from openstack.tests.unit import test_proxy_base from otcextensions.sdk.volume_backup.v2 import _proxy -from otcextensions.sdk.volume_backup.v2 import backup as _backup from otcextensions.sdk.volume_backup.v2 import backup_policy as _backup_policy from otcextensions.sdk.volume_backup.v2 import backup_task as _backup_task from otcextensions.sdk.volume_backup.v2 import job as _job @@ -25,82 +24,12 @@ def setUp(self): self.proxy = _proxy.Proxy(self.session) -class TestBackup(TestVolumeBackupProxy): - - def test_list(self): - self.verify_list( - self.proxy.backups, _backup.Backup, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', - method_kwargs={ - }, - expected_kwargs={ - 'paginated': True, - 'details': False - } - ) - - # verify list with details - self.verify_list( - self.proxy.backups, _backup.Backup, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', - method_kwargs={ - 'details': True, - }, - expected_kwargs={ - 'paginated': True, - 'details': True - } - ) - - def test_get(self): - self.verify_get( - self.proxy.get_backup, - _backup.Backup, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', - expected_kwargs={ - } - ) - - def test_create(self): - self.verify_create( - self.proxy.create_backup, _backup.Backup, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', - method_kwargs={ - 'instance': 'test', - 'name': 'some_name' - }, - expected_kwargs={ - 'instance': 'test', - 'name': 'some_name' - } - ) - - def test_delete(self): - self.verify_delete( - self.proxy.delete_backup, - _backup.Backup, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', - expected_kwargs={ - } - ) - - def test_restore(self): - self._verify2( - 'otcextensions.sdk.volume_backup.v2.backup.Backup.restore', - self.proxy.restore_backup, - method_args=["volume_id"], - method_kwargs={'volume_id': 'vol_id'}, - expected_args=[self.proxy, 'vol_id'], - expected_kwargs={} - ) - - class TestBackupPolicy(TestVolumeBackupProxy): def test_list(self): self.verify_list( self.proxy.backup_policies, _backup_policy.BackupPolicy, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', + mock_method='openstack.proxy.Proxy._list', method_kwargs={ }, expected_kwargs={ @@ -112,13 +41,13 @@ def test_find(self): self.verify_find( self.proxy.find_backup_policy, _backup_policy.BackupPolicy, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._find', + mock_method='openstack.proxy.Proxy._find', ) def test_create(self): self.verify_create( self.proxy.create_backup_policy, _backup_policy.BackupPolicy, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._create', + mock_method='openstack.proxy.Proxy._create', method_kwargs={ 'name': 'some_name' }, @@ -131,14 +60,14 @@ def test_delete(self): self.verify_delete( self.proxy.delete_backup_policy, _backup_policy.BackupPolicy, True, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._delete', + mock_method='openstack.proxy.Proxy._delete', expected_kwargs={ } ) def test_update(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._update', + 'openstack.proxy.Proxy._update', self.proxy.update_backup_policy, method_args=['INSTANCE'], method_kwargs={'test': 't'}, @@ -160,7 +89,7 @@ def test_execute_policy(self): def test_enable_policy(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._update', + 'openstack.proxy.Proxy._update', self.proxy.enable_policy, method_args=['INSTANCE'], expected_args=[_backup_policy.BackupPolicy, 'INSTANCE'], @@ -172,7 +101,7 @@ def test_enable_policy(self): def test_disable_policy(self): self._verify2( - 'otcextensions.sdk.sdk_proxy.Proxy._update', + 'openstack.proxy.Proxy._update', self.proxy.disable_policy, method_args=['INSTANCE'], expected_args=[_backup_policy.BackupPolicy, 'INSTANCE'], @@ -220,7 +149,7 @@ class TestTask(TestVolumeBackupProxy): def test_list(self): self.verify_list( self.proxy.tasks, _backup_task.BackupTask, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._list', + mock_method='openstack.proxy.Proxy._list', method_args=['pol_id'], expected_kwargs={ 'paginated': False, @@ -235,7 +164,7 @@ def test_get(self): self.verify_get( self.proxy.get_job, _job.Job, - mock_method='otcextensions.sdk.sdk_proxy.Proxy._get', + mock_method='openstack.proxy.Proxy._get', expected_kwargs={ } ) diff --git a/requirements.txt b/requirements.txt index ba5b55501..962cdd9ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -openstacksdk>=0.19.0 # Apache-2.0 +openstacksdk>=0.29.0 # Apache-2.0