Add autoregistering of image

You can specify 'image_username' in 'cluster' section and
image will be registered with needed tags.

Change-Id: I3c52acf8b2b0ed1682b2e7b51f4a1f295cb78a03
This commit is contained in:
Evgeny Sikachev 2016-02-17 17:17:15 +03:00
parent 958e5f4e8e
commit b01dd356f8
4 changed files with 30 additions and 3 deletions

View File

@ -85,8 +85,9 @@ class BaseTestCase(base.BaseTestCase):
super(BaseTestCase, self).setUp()
self._init_clients()
timeouts.Defaults.init_defaults(self.testcase)
self.testcase['ssh_username'] = self.sahara.sahara_client.images.get(
self.nova.get_image_id(self.testcase['image'])).username
self.testcase['ssh_username'] = self.sahara.register_image(
self.nova.get_image_id(self.testcase['image']),
self.testcase).username
self.key = self.testcase.get('key_name')
if self.key is None:
self.private_key, self.public_key = ssh.generate_key_pair()

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import time
import fixtures
@ -167,6 +168,25 @@ class SaharaClient(Client):
if nodegroup.name == name:
return nodegroup.id
def register_image(self, image_id, testcase):
try:
return self.sahara_client.images.get(image_id)
except saharaclient_base.APIException:
print("Image not registered in sahara. Registering and run tests")
if testcase.get('image_username') is not None:
self.sahara_client.images.update_image(
image_id, testcase.get('image_username'),
"Registered by scenario tests")
self.sahara_client.images.update_tags(
image_id, [testcase["plugin_name"],
testcase["plugin_version"]])
else:
raise exc.InvalidContentType(
"Registering of image failed. Please, specify "
"'image_username'. For details see README in scenario "
"tests.")
return self.sahara_client.images.get(image_id)
def is_resource_deleted(self, method, *args, **kwargs):
try:
method(*args, **kwargs)

View File

@ -59,6 +59,10 @@ SCHEMA = {
"ssl_cert": {
"type": "string",
"minLength": 1
},
"image_username": {
"type": "string",
"minLength": 1
}
},
"additionalProperties": False

View File

@ -227,13 +227,15 @@ class TestBase(testtools.TestCase):
self.assertEqual('id_ct',
self.base_scenario._create_cluster_template())
@mock.patch('saharaclient.api.images.ImageManager.get',
return_value=FakeResponse(set_id='image'))
@mock.patch('sahara_tests.scenario.clients.NovaClient.get_image_id',
return_value='mock_image')
@mock.patch('saharaclient.client.Client', return_value=FakeSaharaClient())
@mock.patch('saharaclient.api.clusters.ClusterManager.create',
return_value=FakeResponse(set_id='id_cluster'))
def test__create_cluster(self, mock_cluster_manager, mock_saharaclient,
mock_nova):
mock_nova, mock_image):
self.base_scenario._init_clients()
self.assertEqual('id_cluster',
self.base_scenario._create_cluster('id_ct'))