Merge "Replace ' with " in rally/[objects,ui,verification]"
This commit is contained in:
commit
d23a7e449c
@ -134,23 +134,23 @@ class Task(object):
|
||||
db.task_delete(uuid, status=status)
|
||||
|
||||
def _update(self, values):
|
||||
self.task = db.task_update(self.task['uuid'], values)
|
||||
self.task = db.task_update(self.task["uuid"], values)
|
||||
|
||||
def update_status(self, status):
|
||||
self._update({'status': status})
|
||||
self._update({"status": status})
|
||||
|
||||
def update_verification_log(self, log):
|
||||
self._update({'verification_log': json.dumps(log)})
|
||||
self._update({"verification_log": json.dumps(log)})
|
||||
|
||||
def set_failed(self, log=""):
|
||||
self._update({'status': consts.TaskStatus.FAILED,
|
||||
'verification_log': json.dumps(log)})
|
||||
self._update({"status": consts.TaskStatus.FAILED,
|
||||
"verification_log": json.dumps(log)})
|
||||
|
||||
def get_results(self):
|
||||
return db.task_result_get_all_by_uuid(self.task["uuid"])
|
||||
|
||||
def append_results(self, key, value):
|
||||
db.task_result_create(self.task['uuid'], key, value)
|
||||
db.task_result_create(self.task["uuid"], key, value)
|
||||
|
||||
def delete(self, status=None):
|
||||
db.task_delete(self.task['uuid'], status=status)
|
||||
db.task_delete(self.task["uuid"], status=status)
|
||||
|
@ -38,7 +38,7 @@ class Verification(object):
|
||||
return cls(db.verification_get(uuid))
|
||||
|
||||
def delete(self):
|
||||
db.verification_delete(self.db_object['uuid'])
|
||||
db.verification_delete(self.db_object["uuid"])
|
||||
|
||||
def _update(self, **values):
|
||||
self.db_object = db.verification_update(self.uuid, values)
|
||||
@ -61,7 +61,7 @@ class Verification(object):
|
||||
|
||||
# create db object for results
|
||||
data = total.copy()
|
||||
data['test_cases'] = test_cases
|
||||
data["test_cases"] = test_cases
|
||||
db.verification_result_create(self.uuid, data)
|
||||
|
||||
def get_results(self):
|
||||
|
@ -48,6 +48,6 @@ def main(*args):
|
||||
exit(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
main(*args)
|
||||
|
@ -38,4 +38,4 @@ def create_report(results):
|
||||
with open(template_path) as f:
|
||||
template = mako.template.Template(f.read(), strict_undefined=True)
|
||||
output = template.render(**template_kw)
|
||||
return output.encode('utf8')
|
||||
return output.encode("utf8")
|
||||
|
@ -35,15 +35,15 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
image_opts = [
|
||||
cfg.StrOpt('cirros_version',
|
||||
default='0.3.2',
|
||||
help='Version of cirros image'),
|
||||
cfg.StrOpt('cirros_image',
|
||||
default='cirros-0.3.2-x86_64-disk.img',
|
||||
help='Cirros image name'),
|
||||
cfg.StrOpt("cirros_version",
|
||||
default="0.3.2",
|
||||
help="Version of cirros image"),
|
||||
cfg.StrOpt("cirros_image",
|
||||
default="cirros-0.3.2-x86_64-disk.img",
|
||||
help="Cirros image name"),
|
||||
]
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(image_opts, 'image')
|
||||
CONF.register_opts(image_opts, "image")
|
||||
|
||||
|
||||
class TempestConfigCreationFailure(exceptions.RallyException):
|
||||
@ -53,23 +53,23 @@ class TempestConfigCreationFailure(exceptions.RallyException):
|
||||
class TempestConf(object):
|
||||
|
||||
def __init__(self, deployment):
|
||||
self.endpoint = db.deployment_get(deployment)['admin']
|
||||
self.endpoint = db.deployment_get(deployment)["admin"]
|
||||
self.clients = osclients.Clients(objects.Endpoint(**self.endpoint))
|
||||
try:
|
||||
self.keystoneclient = self.clients.verified_keystone()
|
||||
except exceptions.InvalidAdminException:
|
||||
msg = (_("Admin permission is required to generate tempest "
|
||||
"configuration file. User %s doesn't have admin role.") %
|
||||
self.endpoint['username'])
|
||||
self.endpoint["username"])
|
||||
raise TempestConfigCreationFailure(msg)
|
||||
|
||||
self.available_services = self.clients.services().values()
|
||||
|
||||
self.conf = configparser.ConfigParser()
|
||||
self.conf.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
|
||||
self.conf.read(os.path.join(os.path.dirname(__file__), "config.ini"))
|
||||
self.deployment = deployment
|
||||
self.data_path = os.path.join(os.path.expanduser('~'), '.rally',
|
||||
'tempest', 'data')
|
||||
self.data_path = os.path.join(os.path.expanduser("~"), ".rally",
|
||||
"tempest", "data")
|
||||
if not os.path.exists(self.data_path):
|
||||
os.makedirs(self.data_path)
|
||||
self.img_path = os.path.join(self.data_path,
|
||||
@ -78,83 +78,83 @@ class TempestConf(object):
|
||||
self._load_img()
|
||||
|
||||
def _load_img(self):
|
||||
cirros_url = ('http://download.cirros-cloud.net/%s/%s' %
|
||||
cirros_url = ("http://download.cirros-cloud.net/%s/%s" %
|
||||
(CONF.image.cirros_version,
|
||||
CONF.image.cirros_image))
|
||||
try:
|
||||
response = requests.get(cirros_url, stream=True)
|
||||
except requests.ConnectionError as err:
|
||||
msg = _('Error on downloading cirros image, possibly'
|
||||
' no connection to Internet with message %s') % str(err)
|
||||
msg = _("Error on downloading cirros image, possibly"
|
||||
" no connection to Internet with message %s") % str(err)
|
||||
raise TempestConfigCreationFailure(msg)
|
||||
if response.status_code == 200:
|
||||
with open(self.img_path + '.tmp', 'wb') as img_file:
|
||||
with open(self.img_path + ".tmp", "wb") as img_file:
|
||||
for chunk in response.iter_content(chunk_size=1024):
|
||||
if chunk: # filter out keep-alive new chunks
|
||||
img_file.write(chunk)
|
||||
img_file.flush()
|
||||
os.rename(self.img_path + '.tmp', self.img_path)
|
||||
os.rename(self.img_path + ".tmp", self.img_path)
|
||||
else:
|
||||
if response.status_code == 404:
|
||||
msg = _('Error on downloading cirros image, possibly'
|
||||
'invalid cirros_version or cirros_image in rally.conf')
|
||||
msg = _("Error on downloading cirros image, possibly"
|
||||
"invalid cirros_version or cirros_image in rally.conf")
|
||||
else:
|
||||
msg = _('Error on downloading cirros image, '
|
||||
'HTTP error code %s') % response.getcode()
|
||||
msg = _("Error on downloading cirros image, "
|
||||
"HTTP error code %s") % response.getcode()
|
||||
raise TempestConfigCreationFailure(msg)
|
||||
|
||||
def _get_url(self, servicename):
|
||||
services_type2name_map = self.clients.services()
|
||||
for service in self.keystoneclient.auth_ref['serviceCatalog']:
|
||||
if services_type2name_map.get(service['type']) == servicename:
|
||||
for service in self.keystoneclient.auth_ref["serviceCatalog"]:
|
||||
if services_type2name_map.get(service["type"]) == servicename:
|
||||
return service["endpoints"][0]["publicURL"]
|
||||
|
||||
def _set_default(self):
|
||||
lock_path = os.path.join(self.data_path,
|
||||
'lock_files_%s' % self.deployment)
|
||||
"lock_files_%s" % self.deployment)
|
||||
if not os.path.exists(lock_path):
|
||||
os.makedirs(lock_path)
|
||||
self.conf.set('DEFAULT', 'lock_path', lock_path)
|
||||
self.conf.set("DEFAULT", "lock_path", lock_path)
|
||||
|
||||
def _set_boto(self, section_name='boto'):
|
||||
self.conf.set(section_name, 'ec2_url', self._get_url('ec2'))
|
||||
self.conf.set(section_name, 's3_url', self._get_url('s3'))
|
||||
materials_path = os.path.join(self.data_path, 's3materials')
|
||||
self.conf.set(section_name, 's3_materials_path', materials_path)
|
||||
def _set_boto(self, section_name="boto"):
|
||||
self.conf.set(section_name, "ec2_url", self._get_url("ec2"))
|
||||
self.conf.set(section_name, "s3_url", self._get_url("s3"))
|
||||
materials_path = os.path.join(self.data_path, "s3materials")
|
||||
self.conf.set(section_name, "s3_materials_path", materials_path)
|
||||
# TODO(olkonami): find out how can we get ami, ari, aki manifest files
|
||||
|
||||
def _set_compute_images(self, section_name='compute'):
|
||||
def _set_compute_images(self, section_name="compute"):
|
||||
glanceclient = self.clients.glance()
|
||||
image_list = [img for img in glanceclient.images.list()
|
||||
if img.status.lower() == 'active' and
|
||||
img.name is not None and 'cirros' in img.name]
|
||||
if img.status.lower() == "active" and
|
||||
img.name is not None and "cirros" in img.name]
|
||||
# Upload new images if there are no
|
||||
# necessary images in the cloud (cirros)
|
||||
while len(image_list) < 2:
|
||||
now = (datetime.datetime.fromtimestamp(time.time()).
|
||||
strftime('%Y_%m_%d_%H_%M_%S'))
|
||||
strftime("%Y_%m_%d_%H_%M_%S"))
|
||||
try:
|
||||
image = glanceclient.images.create(name=('cirros_%s' % now),
|
||||
disk_format='qcow2',
|
||||
container_format='bare')
|
||||
image.update(data=open(self.img_path, 'rb'))
|
||||
image = glanceclient.images.create(name=("cirros_%s" % now),
|
||||
disk_format="qcow2",
|
||||
container_format="bare")
|
||||
image.update(data=open(self.img_path, "rb"))
|
||||
image_list.append(image)
|
||||
except Exception as e:
|
||||
msg = _("There are no desired images (cirros) or only one and "
|
||||
"new image could not be created.\n"
|
||||
"Reason: %s") % getattr(e, "message", "unknown")
|
||||
raise TempestConfigCreationFailure(msg)
|
||||
self.conf.set(section_name, 'image_ref', image_list[0].id)
|
||||
self.conf.set(section_name, 'image_ref_alt', image_list[1].id)
|
||||
self.conf.set(section_name, "image_ref", image_list[0].id)
|
||||
self.conf.set(section_name, "image_ref_alt", image_list[1].id)
|
||||
|
||||
def _set_compute_flavors(self, section_name='compute'):
|
||||
def _set_compute_flavors(self, section_name="compute"):
|
||||
novaclient = self.clients.nova()
|
||||
flavor_list = sorted(novaclient.flavors.list(),
|
||||
key=lambda flv: flv.ram)
|
||||
# Create new flavors if they are missing
|
||||
while len(flavor_list) < 2:
|
||||
now = (datetime.datetime.fromtimestamp(time.time()).
|
||||
strftime('%Y_%m_%d_%H_%M_%S'))
|
||||
strftime("%Y_%m_%d_%H_%M_%S"))
|
||||
try:
|
||||
flv = novaclient.flavors.create("m1.tiny_%s" % now, 512, 1, 1)
|
||||
flavor_list.append(flv)
|
||||
@ -163,79 +163,79 @@ class TempestConf(object):
|
||||
"new flavor could not be created.\n"
|
||||
"Reason: %s") % getattr(e, "message", "unknown")
|
||||
raise TempestConfigCreationFailure(msg)
|
||||
self.conf.set(section_name, 'flavor_ref', flavor_list[0].id)
|
||||
self.conf.set(section_name, 'flavor_ref_alt', flavor_list[1].id)
|
||||
self.conf.set(section_name, "flavor_ref", flavor_list[0].id)
|
||||
self.conf.set(section_name, "flavor_ref_alt", flavor_list[1].id)
|
||||
|
||||
def _set_compute_ssh_connect_method(self, section_name='compute'):
|
||||
if 'neutron' in self.available_services:
|
||||
self.conf.set(section_name, 'ssh_connect_method', 'floating')
|
||||
def _set_compute_ssh_connect_method(self, section_name="compute"):
|
||||
if "neutron" in self.available_services:
|
||||
self.conf.set(section_name, "ssh_connect_method", "floating")
|
||||
else:
|
||||
self.conf.set(section_name, 'ssh_connect_method', 'fixed')
|
||||
self.conf.set(section_name, "ssh_connect_method", "fixed")
|
||||
|
||||
def _set_compute_admin(self, section_name='compute-admin'):
|
||||
self.conf.set(section_name, 'username', self.endpoint['username'])
|
||||
self.conf.set(section_name, 'password', self.endpoint['password'])
|
||||
self.conf.set(section_name, 'tenant_name',
|
||||
self.endpoint['tenant_name'])
|
||||
def _set_compute_admin(self, section_name="compute-admin"):
|
||||
self.conf.set(section_name, "username", self.endpoint["username"])
|
||||
self.conf.set(section_name, "password", self.endpoint["password"])
|
||||
self.conf.set(section_name, "tenant_name",
|
||||
self.endpoint["tenant_name"])
|
||||
|
||||
def _set_identity(self, section_name='identity'):
|
||||
self.conf.set(section_name, 'username', self.endpoint['username'])
|
||||
self.conf.set(section_name, 'password', self.endpoint['password'])
|
||||
self.conf.set(section_name, 'tenant_name',
|
||||
self.endpoint['tenant_name'])
|
||||
self.conf.set(section_name, 'admin_username',
|
||||
self.endpoint['username'])
|
||||
self.conf.set(section_name, 'admin_password',
|
||||
self.endpoint['password'])
|
||||
self.conf.set(section_name, 'admin_tenant_name',
|
||||
self.endpoint['tenant_name'])
|
||||
self.conf.set(section_name, 'uri', self.endpoint['auth_url'])
|
||||
self.conf.set(section_name, 'uri_v3',
|
||||
self.endpoint['auth_url'].replace('/v2.0', '/v3'))
|
||||
def _set_identity(self, section_name="identity"):
|
||||
self.conf.set(section_name, "username", self.endpoint["username"])
|
||||
self.conf.set(section_name, "password", self.endpoint["password"])
|
||||
self.conf.set(section_name, "tenant_name",
|
||||
self.endpoint["tenant_name"])
|
||||
self.conf.set(section_name, "admin_username",
|
||||
self.endpoint["username"])
|
||||
self.conf.set(section_name, "admin_password",
|
||||
self.endpoint["password"])
|
||||
self.conf.set(section_name, "admin_tenant_name",
|
||||
self.endpoint["tenant_name"])
|
||||
self.conf.set(section_name, "uri", self.endpoint["auth_url"])
|
||||
self.conf.set(section_name, "uri_v3",
|
||||
self.endpoint["auth_url"].replace("/v2.0", "/v3"))
|
||||
|
||||
def _set_network(self, section_name='network'):
|
||||
if 'neutron' in self.available_services:
|
||||
def _set_network(self, section_name="network"):
|
||||
if "neutron" in self.available_services:
|
||||
neutron = self.clients.neutron()
|
||||
public_net = [net for net in neutron.list_networks()['networks'] if
|
||||
net['status'] == 'ACTIVE' and
|
||||
net['router:external'] is True]
|
||||
public_net = [net for net in neutron.list_networks()["networks"] if
|
||||
net["status"] == "ACTIVE" and
|
||||
net["router:external"] is True]
|
||||
if public_net:
|
||||
net_id = public_net[0]['id']
|
||||
self.conf.set(section_name, 'public_network_id', net_id)
|
||||
net_id = public_net[0]["id"]
|
||||
self.conf.set(section_name, "public_network_id", net_id)
|
||||
public_router = neutron.list_routers(
|
||||
network_id=net_id)['routers'][0]
|
||||
self.conf.set(section_name, 'public_router_id',
|
||||
public_router['id'])
|
||||
subnets = neutron.list_subnets(network_id=net_id)['subnets']
|
||||
network_id=net_id)["routers"][0]
|
||||
self.conf.set(section_name, "public_router_id",
|
||||
public_router["id"])
|
||||
subnets = neutron.list_subnets(network_id=net_id)["subnets"]
|
||||
if subnets:
|
||||
subnet = subnets[0]
|
||||
else:
|
||||
# TODO(akurilin): create public subnet
|
||||
LOG.warn('No public subnet is found.')
|
||||
LOG.warn("No public subnet is found.")
|
||||
else:
|
||||
subnets = neutron.list_subnets()['subnets']
|
||||
subnets = neutron.list_subnets()["subnets"]
|
||||
if subnets:
|
||||
subnet = subnets[0]
|
||||
else:
|
||||
# TODO(akurilin): create subnet
|
||||
LOG.warn('No subnet is found.')
|
||||
self.conf.set(section_name, 'default_network', subnet['cidr'])
|
||||
LOG.warn("No subnet is found.")
|
||||
self.conf.set(section_name, "default_network", subnet["cidr"])
|
||||
else:
|
||||
network = self.clients.nova().networks.list()[0]
|
||||
self.conf.set(section_name, 'default_network', network.cidr)
|
||||
self.conf.set(section_name, "default_network", network.cidr)
|
||||
|
||||
def _set_service_available(self, section_name='service_available'):
|
||||
services = ['neutron', 'heat', 'ceilometer', 'swift',
|
||||
'cinder', 'nova', 'glance']
|
||||
def _set_service_available(self, section_name="service_available"):
|
||||
services = ["neutron", "heat", "ceilometer", "swift",
|
||||
"cinder", "nova", "glance"]
|
||||
for service in services:
|
||||
self.conf.set(section_name, service,
|
||||
str(service in self.available_services))
|
||||
horizon_url = ('http://' +
|
||||
parse.urlparse(self.endpoint['auth_url']).hostname)
|
||||
horizon_url = ("http://" +
|
||||
parse.urlparse(self.endpoint["auth_url"]).hostname)
|
||||
horizon_availability = (requests.get(horizon_url).status_code == 200)
|
||||
# convert boolean to string because ConfigParser fails
|
||||
# on attempt to get option with boolean value
|
||||
self.conf.set(section_name, 'horizon', str(horizon_availability))
|
||||
self.conf.set(section_name, "horizon", str(horizon_availability))
|
||||
|
||||
def write_config(self, file_name):
|
||||
with open(file_name, "w+") as f:
|
||||
@ -243,7 +243,7 @@ class TempestConf(object):
|
||||
|
||||
def generate(self, file_name=None):
|
||||
for name, func in inspect.getmembers(self, predicate=inspect.ismethod):
|
||||
if name.startswith('_set_'):
|
||||
if name.startswith("_set_"):
|
||||
func()
|
||||
if file_name:
|
||||
self.write_config(file_name)
|
||||
|
@ -90,8 +90,8 @@ class JsonOutput(testtools.TestResult):
|
||||
_exc_str = self.formatErr(err)
|
||||
failure_type = "%s.%s" % (err[0].__module__, err[1].__name__)
|
||||
self._format_result(test.id(), test_time, STATUS_ERROR, output,
|
||||
failure={'type': failure_type,
|
||||
'log': _exc_str})
|
||||
failure={"type": failure_type,
|
||||
"log": _exc_str})
|
||||
|
||||
def addFailure(self, test, err):
|
||||
self.failure_count += 1
|
||||
@ -104,11 +104,11 @@ class JsonOutput(testtools.TestResult):
|
||||
output = test.id()
|
||||
failure_type = "%s.%s" % (err[0].__module__, err[0].__name__)
|
||||
self._format_result(test.id(), test_time, STATUS_FAIL, output,
|
||||
failure={'type': failure_type, 'log': _exc_str})
|
||||
failure={"type": failure_type, "log": _exc_str})
|
||||
|
||||
def formatErr(self, err):
|
||||
exctype, value, tb = err
|
||||
return ''.join(traceback.format_exception(exctype, value, tb))
|
||||
return "".join(traceback.format_exception(exctype, value, tb))
|
||||
|
||||
def stopTestRun(self):
|
||||
super(JsonOutput, self).stopTestRun()
|
||||
@ -119,9 +119,9 @@ class JsonOutput(testtools.TestResult):
|
||||
"skipped": self.skip_count, "success": self.success_count,
|
||||
"failures": self.failure_count, "time": self.total_time}
|
||||
if self.results_file:
|
||||
with open(self.results_file, 'wb') as results_file:
|
||||
output = jsonutils.dumps({'total': total,
|
||||
'test_cases': self.test_cases})
|
||||
with open(self.results_file, "wb") as results_file:
|
||||
output = jsonutils.dumps({"total": total,
|
||||
"test_cases": self.test_cases})
|
||||
results_file.write(output)
|
||||
|
||||
def startTestRun(self):
|
||||
@ -135,12 +135,12 @@ class FileAccumulator(testtools.StreamResult):
|
||||
self.route_codes = collections.defaultdict(io.BytesIO)
|
||||
|
||||
def status(self, **kwargs):
|
||||
if kwargs.get('file_name') != 'stdout':
|
||||
if kwargs.get("file_name") != "stdout":
|
||||
return
|
||||
file_bytes = kwargs.get('file_bytes')
|
||||
file_bytes = kwargs.get("file_bytes")
|
||||
if not file_bytes:
|
||||
return
|
||||
route_code = kwargs.get('route_code')
|
||||
route_code = kwargs.get("route_code")
|
||||
stream = self.route_codes[route_code]
|
||||
stream.write(file_bytes)
|
||||
|
||||
@ -148,20 +148,20 @@ class FileAccumulator(testtools.StreamResult):
|
||||
def main(subunit_log_file):
|
||||
fd, results_file = tempfile.mkstemp()
|
||||
result = JsonOutput(results_file)
|
||||
stream = open(subunit_log_file, 'rb')
|
||||
stream = open(subunit_log_file, "rb")
|
||||
|
||||
# Feed the subunit stream through both a V1 and V2 parser.
|
||||
# Depends on having the v2 capable libraries installed.
|
||||
# First V2.
|
||||
# Non-v2 content and captured non-test output will be presented as file
|
||||
# segments called stdout.
|
||||
suite = subunit.ByteStreamToStreamResult(stream, non_subunit_name='stdout')
|
||||
suite = subunit.ByteStreamToStreamResult(stream, non_subunit_name="stdout")
|
||||
# The JSON output code is in legacy mode.
|
||||
raw_result = testtools.StreamToExtendedDecorator(result)
|
||||
# Divert non-test output
|
||||
accumulator = FileAccumulator()
|
||||
result = testtools.StreamResultRouter(raw_result)
|
||||
result.add_rule(accumulator, 'test_id', test_id=None)
|
||||
result.add_rule(accumulator, "test_id", test_id=None)
|
||||
result.startTestRun()
|
||||
suite.run(result)
|
||||
# Now reprocess any found stdout content as V1 subunit
|
||||
@ -170,7 +170,7 @@ def main(subunit_log_file):
|
||||
suite = subunit.ProtocolTestCase(bytes_io)
|
||||
suite.run(result)
|
||||
result.stopTestRun()
|
||||
with open(results_file, 'rb') as temp_results_file:
|
||||
with open(results_file, "rb") as temp_results_file:
|
||||
data = temp_results_file.read()
|
||||
try:
|
||||
os.unlink(results_file)
|
||||
|
@ -235,7 +235,7 @@ class Tempest(object):
|
||||
stdout=subprocess.PIPE).communicate()[0]
|
||||
|
||||
tests = set()
|
||||
for test in raw_results.split('\n'):
|
||||
for test in raw_results.split("\n"):
|
||||
if test.startswith("tempest."):
|
||||
index = test.find("[")
|
||||
if index != -1:
|
||||
@ -250,7 +250,7 @@ class Tempest(object):
|
||||
log_file_raw = log_file or self.log_file_raw
|
||||
if os.path.isfile(log_file_raw):
|
||||
data = jsonutils.loads(subunit2json.main(log_file_raw))
|
||||
return data['total'], data['test_cases']
|
||||
return data["total"], data["test_cases"]
|
||||
else:
|
||||
LOG.error("JSON-log file not found.")
|
||||
return None, None
|
||||
|
Loading…
Reference in New Issue
Block a user