"Fossies" - the Fresh Open Source Software Archive

Member "magnum-8.1.0/magnum/tests/unit/api/utils.py" (1 Oct 2019, 3543 Bytes) of package /linux/misc/openstack/magnum-8.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "utils.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.0_vs_9.1.0.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 """
   13 Utils for testing the API service.
   14 """
   15 import datetime
   16 
   17 import pytz
   18 
   19 from magnum.api.controllers.v1 import bay as bay_controller
   20 from magnum.api.controllers.v1 import baymodel as baymodel_controller
   21 from magnum.api.controllers.v1 import cluster as cluster_controller
   22 from magnum.api.controllers.v1 import cluster_template as cluster_tmp_ctrl
   23 from magnum.api.controllers.v1 import federation as federation_controller
   24 from magnum.tests.unit.db import utils
   25 
   26 
   27 def remove_internal(values, internal):
   28     # NOTE(yuriyz): internal attributes should not be posted, except uuid
   29     int_attr = [attr.lstrip('/') for attr in internal if attr != '/uuid']
   30     return {k: v for (k, v) in values.items() if k not in int_attr}
   31 
   32 
   33 def baymodel_post_data(**kw):
   34     baymodel = utils.get_test_cluster_template(**kw)
   35     internal = baymodel_controller.BayModelPatchType.internal_attrs()
   36     return remove_internal(baymodel, internal)
   37 
   38 
   39 def cluster_template_post_data(**kw):
   40     cluster_template = utils.get_test_cluster_template(**kw)
   41     internal = cluster_tmp_ctrl.ClusterTemplatePatchType.internal_attrs()
   42     return remove_internal(cluster_template, internal)
   43 
   44 
   45 def bay_post_data(**kw):
   46     bay = utils.get_test_cluster(**kw)
   47     bay['baymodel_id'] = kw.get('baymodel_id', bay['cluster_template_id'])
   48     bay['bay_create_timeout'] = kw.get('bay_create_timeout', 15)
   49     del bay['cluster_template_id']
   50     del bay['create_timeout']
   51     internal = bay_controller.BayPatchType.internal_attrs()
   52     return remove_internal(bay, internal)
   53 
   54 
   55 def cluster_post_data(**kw):
   56     cluster = utils.get_test_cluster(**kw)
   57     cluster['create_timeout'] = kw.get('create_timeout', 15)
   58     internal = cluster_controller.ClusterPatchType.internal_attrs()
   59     return remove_internal(cluster, internal)
   60 
   61 
   62 def cert_post_data(**kw):
   63     return {
   64         'cluster_uuid': kw.get('cluster_uuid',
   65                                '5d12f6fd-a196-4bf0-ae4c-1f639a523a52'),
   66         'csr': kw.get('csr', 'fake-csr'),
   67         'pem': kw.get('pem', 'fake-pem')
   68     }
   69 
   70 
   71 def quota_post_data(**kw):
   72     return utils.get_test_quota(**kw)
   73 
   74 
   75 def mservice_get_data(**kw):
   76     """Simulate what the RPC layer will get from DB """
   77     faketime = datetime.datetime(2001, 1, 1, tzinfo=pytz.UTC)
   78     return {
   79         'binary': kw.get('binary', 'magnum-conductor'),
   80         'host': kw.get('host', 'fake-host'),
   81         'id': kw.get('id', 13),
   82         'report_count': kw.get('report_count', 13),
   83         'disabled': kw.get('disabled', False),
   84         'disabled_reason': kw.get('disabled_reason', None),
   85         'forced_down': kw.get('forced_down', False),
   86         'last_seen_at': kw.get('last_seen_at', faketime),
   87         'created_at': kw.get('created_at', faketime),
   88         'updated_at': kw.get('updated_at', faketime),
   89     }
   90 
   91 
   92 def federation_post_data(**kw):
   93     federation = utils.get_test_federation(**kw)
   94     internal = federation_controller.FederationPatchType.internal_attrs()
   95     return remove_internal(federation, internal)