/usr/lib/python2.7/dist-packages/saharaclient/tests/unit/test_cluster_templates.py is in python-saharaclient 0.18.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | # Copyright (c) 2014 Mirantis Inc.
#
# 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 saharaclient.api import cluster_templates as ct
from saharaclient.tests.unit import base
import json
class ClusterTemplateTest(base.BaseTestCase):
body = {
'name': 'name',
'description': 'description',
'plugin_name': 'plugin',
'hadoop_version': '1',
'node_groups': {
'name': 'master-node',
'flavor_id': '2',
'node_processes': ['namenode'],
'count': 1
},
"use_autoconfig": False,
"domain_name": 'domain.org.'
}
update_json = {
"cluster_template": {
'name': 'UpdatedName',
'description': 'Updated description',
'plugin_name': 'plugin',
'hadoop_version': '1',
'node_groups': {
'name': 'master-node',
'flavor_id': '3',
'node_processes': ['namenode', 'datanode'],
'count': 1
},
"use_autoconfig": True,
"domain_name": 'domain.org.'
}
}
def test_create_cluster_template(self):
url = self.URL + '/cluster-templates'
self.responses.post(url, status_code=202,
json={'cluster_template': self.body})
resp = self.client.cluster_templates.create(**self.body)
self.assertEqual(url, self.responses.last_request.url)
self.assertEqual(self.body,
json.loads(self.responses.last_request.body))
self.assertIsInstance(resp, ct.ClusterTemplate)
self.assertFields(self.body, resp)
def test_cluster_template_list(self):
url = self.URL + '/cluster-templates'
self.responses.get(url, json={'cluster_templates': [self.body]})
resp = self.client.cluster_templates.list()
self.assertEqual(url, self.responses.last_request.url)
self.assertIsInstance(resp[0], ct.ClusterTemplate)
self.assertFields(self.body, resp[0])
def test_cluster_template_get(self):
url = self.URL + '/cluster-templates/id'
self.responses.get(url, json={'cluster_template': self.body})
resp = self.client.cluster_templates.get('id')
self.assertEqual(url, self.responses.last_request.url)
self.assertIsInstance(resp, ct.ClusterTemplate)
self.assertFields(self.body, resp)
def test_cluster_template_delete(self):
url = self.URL + '/cluster-templates/id'
self.responses.delete(url, status_code=204)
self.client.cluster_templates.delete('id')
self.assertEqual(url, self.responses.last_request.url)
def test_cluster_template_update(self):
url = self.URL + '/cluster-templates'
self.responses.post(url, status_code=202,
json={'cluster_template': self.body})
resp = self.client.cluster_templates.create(**self.body)
update_url = self.URL + '/cluster-templates/id'
self.responses.put(update_url, status_code=202, json=self.update_json)
# check that all parameters will be updated
updated = self.client.cluster_templates.update(
"id",
resp.name,
resp.plugin_name,
resp.hadoop_version,
description=getattr(resp, "description", None),
cluster_configs=getattr(resp, "cluster_configs", None),
node_groups=getattr(resp, "node_groups", None),
anti_affinity=getattr(resp, "anti_affinity", None),
net_id=getattr(resp, "neutron_management_network", None),
default_image_id=getattr(resp, "default_image_id", None),
use_autoconfig=True,
domain_name=getattr(resp, "domain_name", None)
)
self.assertIsInstance(updated, ct.ClusterTemplate)
self.assertFields(self.update_json["cluster_template"], updated)
# check that parameters will not be updated
self.client.cluster_templates.update("id")
self.assertEqual(update_url, self.responses.last_request.url)
self.assertEqual({},
json.loads(self.responses.last_request.body))
# check that all parameters will be unset
unset_json = {
'anti_affinity': None, 'cluster_configs': None,
'default_image_id': None, 'description': None,
'hadoop_version': None, 'is_protected': None, 'is_public': None,
'name': None, 'net_id': None,
'node_groups': None, 'plugin_name': None, 'shares': None,
'use_autoconfig': None, 'domain_name': None}
req_json = unset_json.copy()
req_json['neutron_management_network'] = req_json.pop('net_id')
self.client.cluster_templates.update("id", **unset_json)
self.assertEqual(update_url, self.responses.last_request.url)
self.assertEqual(req_json,
json.loads(self.responses.last_request.body))
|