Commit df0045d8 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Fix all minor typos and modifications in tests

parent 87f1be2a
......@@ -33,7 +33,7 @@
import logging
from sys import argv, exit, stdout
from os.path import basename
from os.path import basename, exists
from inspect import getargspec
from kamaki.cli.argument import ArgumentParseManager
......@@ -194,10 +194,9 @@ def _setup_logging(silent=False, debug=False, verbose=False, include=False):
def _check_config_version(cnf):
guess = cnf.guess_version()
if guess < 0.9:
if exists(cnf.path) and guess < 0.9:
print('Config file format version >= 9.0 is required')
print('Configuration file "%s" format is not up to date' % (
cnf.path))
print('Configuration file: %s' % cnf.path)
print('but kamaki can fix this:')
print('Calculating changes while preserving information')
lost_terms = cnf.rescue_old_file()
......@@ -234,6 +233,10 @@ def _init_session(arguments, is_non_API=False):
global _verbose
_verbose = arguments['verbose'].value
_cnf = arguments['config']
if _help or is_non_API:
return None, None
_check_config_version(_cnf.value)
global _colors
......@@ -244,16 +247,13 @@ def _init_session(arguments, is_non_API=False):
_silent = arguments['silent'].value
_setup_logging(_silent, _debug, _verbose, _include)
if _help or is_non_API:
return None, None
cloud = arguments['cloud'].value or _cnf.value.get(
'global', 'default_cloud')
if not cloud:
num_of_clouds = len(_cnf.value.keys('cloud'))
if num_of_clouds == 1:
cloud = _cnf.value.keys('cloud')[0]
else:
elif num_of_clouds > 1:
raise CLIError(
'Found %s clouds but none of them is set as default' % (
num_of_clouds),
......@@ -268,12 +268,15 @@ def _init_session(arguments, is_non_API=False):
' kamaki --cloud=<cloud name> ...'])
if not cloud in _cnf.value.keys('cloud'):
raise CLIError(
'No cloud "%s" is configured' % cloud,
'No cloud%s is configured' % ((' "%s"' % cloud) if cloud else ''),
importance=3, details=[
'To configure a new cloud, find and set the',
'To configure a new cloud "%s", find and set the' % (
cloud or '<cloud name>'),
'single authentication URL and token:',
' kamaki config set cloud.%s.url <URL>' % cloud,
' kamaki config set cloud.%s.token <t0k3n>' % cloud])
' kamaki config set cloud.%s.url <URL>' % (
cloud or '<cloud name>'),
' kamaki config set cloud.%s.token <t0k3n>' % (
cloud or '<cloud name>')])
auth_args = dict()
for term in ('url', 'token'):
try:
......
......@@ -326,14 +326,12 @@ class image_register(_init_image, _optional_json):
ptoken = self.client.token
if getattr(self, 'auth_base', False):
pithos_endpoints = self.auth_base.get_service_endpoints(
self.config.get('pithos', 'type'),
self.config.get('pithos', 'version'))
'object-store')
purl = pithos_endpoints['publicURL']
else:
purl = self.config.get('file', 'url')\
or self.config.get('pithos', 'url')
if not purl:
raise CLIBaseUrlError(service='pithos')
purl = self.config.get_cloud('pithos', 'url')
if not purl:
raise CLIBaseUrlError(service='pithos')
return PithosClient(purl, ptoken, self._get_user_id(), container)
def _store_remote_metafile(self, pclient, remote_path, metadata):
......
......@@ -1947,11 +1947,9 @@ class file_versioning_get(_file_account_command, _optional_json):
@errors.pithos.container
def _run(self):
self._print(
self.client.get_container_versioning(self.container) if (
self.container) else self.client.get_account_versioning(),
print_dict)
self.client.get_container_versioning(self.container), print_dict)
def main(self, container=None):
def main(self, container):
super(self.__class__, self)._run()
self.container = container
self._run()
......@@ -1971,14 +1969,11 @@ class file_versioning_set(_file_account_command, _optional_output_cmd):
@errors.pithos.connection
@errors.pithos.container
def _run(self, versioning):
if self.container:
self.client.container = self.container
r = self.client.set_container_versioning(versioning)
else:
r = self.client.set_account_versioning(versioning)
self.client.container = self.container
r = self.client.set_container_versioning(versioning)
self._optional_output(r)
def main(self, versioning, container=None):
def main(self, versioning, container):
super(self.__class__, self)._run()
self._run(self._check_versioning(versioning))
......
......@@ -230,14 +230,14 @@ class Config(RawConfigParser):
log.warning('..... config file has an old global section')
return 0.8
log.warning('........ nope')
log.warning('Config file heuristic 2: missing all cloud sections ?')
log.warning('Config file heuristic 2: Any cloud sections ?')
if 'cloud' in sections:
for r in self.keys('cloud'):
log.warning('... found cloud "%s"' % r)
return 0.9
log.warning('........ yep')
log.warning('........ nope')
log.warning('All heuristics failed, cannot decide')
return 0.0
return 0.9
def get_cloud(self, cloud, option):
"""
......
......@@ -153,7 +153,7 @@ class ComputeClient(ComputeRestClient):
"""
command = path4url('metadata', key)
r = self.servers_get(server_id, command)
return r.json['metadata']
return r.json['meta']
def create_server_metadata(self, server_id, key, val):
"""
......@@ -165,13 +165,10 @@ class ComputeClient(ComputeRestClient):
:returns: dict of updated key:val metadata
"""
req = {'metadata': {key: val}}
req = {'meta': {key: val}}
r = self.servers_put(
server_id,
'metadata/' + key,
json_data=req,
success=201)
return r.json['metadata']
server_id, 'metadata/' + key, json_data=req, success=201)
return r.json['meta']
def update_server_metadata(self, server_id, **metadata):
"""
......@@ -183,8 +180,7 @@ class ComputeClient(ComputeRestClient):
"""
req = {'metadata': metadata}
r = self.servers_post(
server_id, 'metadata',
json_data=req, success=201)
server_id, 'metadata', json_data=req, success=201)
return r.json['metadata']
def delete_server_metadata(self, server_id, key):
......@@ -258,7 +254,7 @@ class ComputeClient(ComputeRestClient):
"""
command = path4url('metadata', key)
r = self.images_get(image_id, command)
return r.json['metadata']
return r.json['meta']
def create_image_metadata(self, image_id, key, val):
"""
......@@ -270,9 +266,9 @@ class ComputeClient(ComputeRestClient):
:returns: (dict) updated metadata
"""
req = {'metadata': {key: val}}
req = {'meta': {key: val}}
r = self.images_put(image_id, 'metadata/' + key, json_data=req)
return r.json['metadata']
return r.json['meta']
def update_image_metadata(self, image_id, **metadata):
"""
......
......@@ -42,7 +42,7 @@ class Cyclades(livetest.Generic):
"""Set up a Cyclades test"""
def setUp(self):
print
with open(self['image', 'details']) as f:
with open(self['cmpimage', 'details']) as f:
self.img_details = eval(f.read())
self.img = self.img_details['id']
with open(self['flavor', 'details']) as f:
......@@ -82,7 +82,7 @@ class Cyclades(livetest.Generic):
self.img)
self.server2 = self._create_server(
self.servname2,
self.flavorid + 2,
self.flavorid,
self.img)
super(self.__class__, self).test_000()
......@@ -167,6 +167,7 @@ class Cyclades(livetest.Generic):
def _has_status(self, servid, status):
r = self.client.get_server_details(servid)
#print 'MY STATUS IS ', r['status']
return r['status'] == status
def _wait_for_status(self, servid, status):
......@@ -188,7 +189,7 @@ class Cyclades(livetest.Generic):
c2 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid + 2,
self.flavorid,
self.img)
c3 = SilentEvent(
self._create_server,
......@@ -198,7 +199,7 @@ class Cyclades(livetest.Generic):
c4 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid + 2,
self.flavorid,
self.img)
c5 = SilentEvent(
self._create_server,
......@@ -208,7 +209,7 @@ class Cyclades(livetest.Generic):
c6 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid + 2,
self.flavorid,
self.img)
c7 = SilentEvent(
self._create_server,
......@@ -218,7 +219,7 @@ class Cyclades(livetest.Generic):
c8 = SilentEvent(
self._create_server,
self.servname2,
self.flavorid + 2,
self.flavorid,
self.img)
c1.start()
c2.start()
......@@ -240,8 +241,8 @@ class Cyclades(livetest.Generic):
def _test_0010_create_server(self):
self.assertEqual(self.server1["name"], self.servname1)
self.assertEqual(self.server1["flavorRef"], self.flavorid)
self.assertEqual(self.server1["imageRef"], self.img)
self.assertEqual(self.server1["flavor"], self.flavorid)
self.assertEqual(self.server1["image"], self.img)
self.assertEqual(self.server1["status"], "BUILD")
def test_list_servers(self):
......@@ -252,7 +253,7 @@ class Cyclades(livetest.Generic):
self.img)
self.server2 = self._create_server(
self.servname2,
self.flavorid + 2,
self.flavorid,
self.img)
self._test_0020_list_servers()
......@@ -265,9 +266,9 @@ class Cyclades(livetest.Generic):
for i in range(len(servers)):
for field in (
'created',
'flavorRef',
'flavor',
'hostId',
'imageRef',
'image',
'progress',
'status',
'updated'):
......@@ -297,8 +298,8 @@ class Cyclades(livetest.Generic):
def _test_0040_get_server_details(self):
r = self.client.get_server_details(self.server1['id'])
self.assertEqual(r["name"], self.servname1)
self.assertEqual(r["flavorRef"], self.flavorid)
self.assertEqual(r["imageRef"], self.img)
self.assertEqual(r["flavor"], self.flavorid)
self.assertEqual(r["image"], self.img)
self.assertEqual(r["status"], "ACTIVE")
def test_update_server_name(self):
......@@ -374,10 +375,8 @@ class Cyclades(livetest.Generic):
self._test_0090_get_server_metadata()
def _test_0090_get_server_metadata(self):
self.client.create_server_metadata(
self.server1['id'],
'mymeta_0',
'val_0')
self.client.update_server_metadata(
self.server1['id'], mymeta_0='val_0')
r = self.client.get_server_metadata(self.server1['id'], 'mymeta_0')
self.assertEqual(r['mymeta_0'], 'val_0')
......@@ -390,29 +389,22 @@ class Cyclades(livetest.Generic):
self._test_0100_update_server_metadata()
def _test_0100_update_server_metadata(self):
r1 = self.client.create_server_metadata(
self.server1['id'],
'mymeta3',
'val2')
r1 = self.client.update_server_metadata(
self.server1['id'], mymeta3='val2')
self.assertTrue('mymeta3'in r1)
r2 = self.client.update_server_metadata(
self.server1['id'],
mymeta3='val3')
self.server1['id'], mymeta3='val3')
self.assertTrue(r2['mymeta3'], 'val3')
def test_delete_server_metadata(self):
"""Test delete_server_metadata"""
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self._test_0110_delete_server_metadata()
def _test_0110_delete_server_metadata(self):
r1 = self.client.create_server_metadata(
self.server1['id'],
'mymeta',
'val')
r1 = self.client.update_server_metadata(
self.server1['id'], mymeta='val')
self.assertTrue('mymeta' in r1)
self.client.delete_server_metadata(self.server1['id'], 'mymeta')
try:
......@@ -467,8 +459,8 @@ class Cyclades(livetest.Generic):
def _test_0160_get_image_metadata(self):
r = self.client.get_image_metadata(self.img)
self.assert_dicts_are_deeply_equal(
self.img_details['metadata']['values'], r)
for key, val in self.img_details['metadata']['values'].items():
self.img_details['metadata'], r)
for key, val in self.img_details['metadata'].items():
r = self.client.get_image_metadata(self.img, key)
self.assertEqual(r[key], val)
......@@ -508,7 +500,7 @@ class Cyclades(livetest.Generic):
"""Test get_server_console"""
self.server2 = self._create_server(
self.servname2,
self.flavorid + 2,
self.flavorid,
self.img)
self._wait_for_status(self.server2['id'], 'BUILD')
self._test_0190_get_server_console()
......
......@@ -153,7 +153,7 @@ class Image(livetest.Generic):
if len(img['properties']):
for interm in ('osfamily', 'users', 'root_partition'):
self.assertTrue(interm in img['properties'])
size_max = 1000000000
size_max = 1000000000000
r2 = self.client.list_public(filters=dict(size_max=size_max))
self.assertTrue(len(r2) <= len(r))
for img in r2:
......
......@@ -167,8 +167,8 @@ class Pithos(livetest.Generic):
r = self.client.get_account_quota()
self.assertTrue('x-account-policy-quota' in r)
r = self.client.get_account_versioning()
self.assertTrue('x-account-policy-versioning' in r)
#r = self.client.get_account_versioning()
#self.assertTrue('x-account-policy-versioning' in r)
"""Check if(un)modified_since"""
for format in self.client.DATE_FORMATS:
......@@ -292,7 +292,7 @@ class Pithos(livetest.Generic):
#print(unicode(r))
#r = self.client.get_account_quota()
#self.assertEqual(r['x-account-policy-quota'], newquota)
self.client.set_account_versioning('auto')
#self.client.set_account_versioning('auto')
def test_container_head(self):
"""Test container_HEAD"""
......
......@@ -952,14 +952,14 @@ class PithosClient(PithosRestClient):
'X-Account-Policy-Quota',
exactMatch=True)
def get_account_versioning(self):
"""
:returns: (dict)
"""
return filter_in(
self.get_account_info(),
'X-Account-Policy-Versioning',
exactMatch=True)
#def get_account_versioning(self):
# """
# :returns: (dict)
# """
# return filter_in(
# self.get_account_info(),
# 'X-Account-Policy-Versioning',
# exactMatch=True)
def get_account_meta(self, until=None):
"""
......@@ -990,20 +990,18 @@ class PithosClient(PithosRestClient):
r = self.account_post(update=True, metadata={metakey: ''})
return r.headers
"""
def set_account_quota(self, quota):
""
:param quota: (int)
""
self.account_post(update=True, quota=quota)
"""
def set_account_versioning(self, versioning):
"""
"param versioning: (str)
"""
r = self.account_post(update=True, versioning=versioning)
return r.headers
#def set_account_quota(self, quota):
# """
# :param quota: (int)
# """
# self.account_post(update=True, quota=quota)
#def set_account_versioning(self, versioning):
# """
# :param versioning: (str)
# """
# r = self.account_post(update=True, versioning=versioning)
# return r.headers
def list_containers(self):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment