Enhance the image checks, fix the flavor picking bug

Change-Id: I54e4a6d217877eb5310837ebd44695a46ae18ad8
This commit is contained in:
Yichen Wang 2015-07-24 12:34:52 -07:00
parent 65f0580c41
commit 7b453e5cef
2 changed files with 27 additions and 19 deletions

View File

@ -21,6 +21,7 @@ import traceback
import base_compute import base_compute
import base_network import base_network
import glanceclient.exc as glance_exception
from glanceclient.v2 import client as glanceclient from glanceclient.v2 import client as glanceclient
from kb_config import KBConfig from kb_config import KBConfig
from kb_runner import KBRunner from kb_runner import KBRunner
@ -57,19 +58,16 @@ def check_and_upload_images(cred, cred_testing, server_img_name, client_img_name
img_name_dict = dict(zip(['Server kloud', 'Client kloud'], [server_img_name, client_img_name])) img_name_dict = dict(zip(['Server kloud', 'Client kloud'], [server_img_name, client_img_name]))
for kloud, keystone in keystone_dict.items(): for kloud, keystone in keystone_dict.items():
img_found = False
glance_endpoint = keystone.service_catalog.url_for( glance_endpoint = keystone.service_catalog.url_for(
service_type='image', endpoint_type='publicURL') service_type='image', endpoint_type='publicURL')
glance_client = glanceclient.Client(glance_endpoint, token=keystone.auth_token) glance_client = glanceclient.Client(glance_endpoint, token=keystone.auth_token)
for img in glance_client.images.list(): try:
if img['name'] == img_name_dict[kloud]: # Search for the image
img_found = True glance_client.images.list(filters={'name': img_name_dict[kloud]}).next()
break return True
if img_found and img.visibility != 'public' and CONF.tenants_list: except StopIteration:
LOG.error("Image must be public when running in tenant/user reusing mode.") pass
sys.exit(1)
if not img_found:
# Trying upload images # Trying upload images
LOG.info("Image is not found in %s, trying to upload..." % (kloud)) LOG.info("Image is not found in %s, trying to upload..." % (kloud))
if not os.path.exists('dib/kloudbuster.qcow2'): if not os.path.exists('dib/kloudbuster.qcow2'):
@ -77,11 +75,16 @@ def check_and_upload_images(cred, cred_testing, server_img_name, client_img_name
"to dib/README.rst for how to build image for KloudBuster.") "to dib/README.rst for how to build image for KloudBuster.")
return False return False
with open('dib/kloudbuster.qcow2') as fimage: with open('dib/kloudbuster.qcow2') as fimage:
try:
image = glance_client.images.create(name=img_name_dict[kloud], image = glance_client.images.create(name=img_name_dict[kloud],
disk_format="qcow2", disk_format="qcow2",
container_format="bare", container_format="bare",
visibility='public') visibility='public')
glance_client.images.upload(image['id'], fimage) glance_client.images.upload(image['id'], fimage)
except glance_exception.HTTPForbidden:
LOG.error("Cannot upload image without admin access. Please make sure the "
"image is existed in cloud, and is either public or owned by you.")
sys.exit(1)
return True return True
@ -93,6 +96,7 @@ class Kloud(object):
self.scale_cfg = scale_cfg self.scale_cfg = scale_cfg
self.reusing_tenants = reusing_tenants self.reusing_tenants = reusing_tenants
self.keystone, self.auth_url = create_keystone_client(self.cred) self.keystone, self.auth_url = create_keystone_client(self.cred)
self.flavor_to_use = None
if testing_side: if testing_side:
self.prefix = 'KBc' self.prefix = 'KBc'
self.name = 'Client Kloud' self.name = 'Client Kloud'
@ -290,7 +294,8 @@ class KloudBuster(object):
self.kloud.placement_az, "Round-robin") self.kloud.placement_az, "Round-robin")
for ins in svr_list: for ins in svr_list:
ins.user_data['role'] = 'Server' ins.user_data['role'] = 'Server'
ins.boot_info['flavor_type'] = 'm1.small' if self.tenants_list else 'kb.server' ins.boot_info['flavor_type'] =\
self.kloud.flavor_to_use if self.tenants_list else 'kb.server'
ins.boot_info['user_data'] = str(ins.user_data) ins.boot_info['user_data'] = str(ins.user_data)
elif role == "Client": elif role == "Client":
client_list = self.testing_kloud.get_all_instances() client_list = self.testing_kloud.get_all_instances()
@ -307,7 +312,8 @@ class KloudBuster(object):
ins.user_data['target_shared_interface_ip'] = svr_list[idx].shared_interface_ip ins.user_data['target_shared_interface_ip'] = svr_list[idx].shared_interface_ip
ins.user_data['http_tool'] = ins.config['http_tool'] ins.user_data['http_tool'] = ins.config['http_tool']
ins.user_data['http_tool_configs'] = ins.config['http_tool_configs'] ins.user_data['http_tool_configs'] = ins.config['http_tool_configs']
ins.boot_info['flavor_type'] = 'm1.small' if self.tenants_list else 'kb.client' ins.boot_info['flavor_type'] =\
self.testing_kloud.flavor_to_use if self.tenants_list else 'kb.client'
ins.boot_info['user_data'] = str(ins.user_data) ins.boot_info['user_data'] = str(ins.user_data)
def run(self): def run(self):
@ -333,7 +339,8 @@ class KloudBuster(object):
self.kb_proxy.vm_name = 'KB-PROXY' self.kb_proxy.vm_name = 'KB-PROXY'
self.kb_proxy.user_data['role'] = 'KB-PROXY' self.kb_proxy.user_data['role'] = 'KB-PROXY'
self.kb_proxy.boot_info['flavor_type'] = 'm1.small' if self.tenants_list else 'kb.proxy' self.kb_proxy.boot_info['flavor_type'] =\
self.testing_kloud.flavor_to_use if self.tenants_list else 'kb.proxy'
if self.testing_kloud.placement_az: if self.testing_kloud.placement_az:
self.kb_proxy.boot_info['avail_zone'] = "%s:%s" %\ self.kb_proxy.boot_info['avail_zone'] = "%s:%s" %\
(self.testing_kloud.placement_az, self.topology.clients_rack.split()[0]) (self.testing_kloud.placement_az, self.topology.clients_rack.split()[0])

View File

@ -141,6 +141,7 @@ class User(object):
if flavor_to_use: if flavor_to_use:
LOG.info('Automatically selects flavor %s to instantiate VMs.' % LOG.info('Automatically selects flavor %s to instantiate VMs.' %
(flavor_to_use['name'])) (flavor_to_use['name']))
self.tenant.kloud.flavor_to_use = flavor_to_use['name']
else: else:
LOG.error('Cannot find a flavor which meets the minimum ' LOG.error('Cannot find a flavor which meets the minimum '
'requirements to instantiate VMs.') 'requirements to instantiate VMs.')