def init_undercloud_host(undercloud_ip, key_filename): # Waiting for the undercloud host to be back undercloud = tripleohelper.undercloud.Undercloud(hostname=undercloud_ip, user='******', key_filename=key_filename) # copy our public SSH key to be able later to run our tests undercloud.run('sudo mkdir -p /root/.ssh', retry=600, user='******') undercloud.run('sudo chmod 700 /root/.ssh', user='******') undercloud.run('sudo cp /home/stack/.ssh/authorized_keys /root/.ssh/', user='******')
def push_stack_details(context, undercloud, stack_name='overcloud'): undercloud.yum_install(['git']) repo_url = 'https://github.com/goneri/tripleo-stack-dump' undercloud.run( 'test -d tripleo-stack-dump || git clone ' + repo_url, user='******') undercloud.add_environment_file( user='******', filename='stackrc') undercloud.run( './tripleo-stack-dump/list_nodes_status', user='******') undercloud.run( './tripleo-stack-dump/tripleo-stack-dump ' + stack_name, user='******') with undercloud.open('/home/stack/tripleo-stack-dump.json') as fd: j = job.get( context, id=context.last_job_id).json()['job'] job.update( context, id=context.last_job_id, etag=j['etag'], configuration=json.load(fd))
def cli(os_auth_url, os_username, os_password, os_project_id, config_file, step): config = yaml.load(config_file) logger.setup_logging(config_file=config.get('config_file')) undercloud = None baremetal_factory = None sess = os_utils.ks_session(os_auth_url, os_username, os_password, os_project_id) neutron = os_utils.build_neutron_client(sess) nova_api = os_utils.build_nova_api(sess) provisioner = config['provisioner'] print('step: %s' % step) if step == 'cleanup': purge_existing_ovb(nova_api, neutron) exit(0) if step == 'provisioning': purge_existing_ovb(nova_api, neutron) initialize_network(neutron) undercloud = ovb_undercloud.OVBUndercloud( key_filename=config['ssh']['private_key'] ) undercloud.start( nova_api=nova_api, neutron=neutron, provisioner=config['provisioner'], ip='192.0.2.240', floating_ip=config['undercloud'].get('floating_ip')) undercloud.create_stack_user() baremetal_factory = ovb_baremetal.BaremetalFactory( nova_api, neutron, keypair=config['provisioner']['keypair'], key_filename=config['ssh']['private_key'], security_groups=config['provisioner']['security-groups'], os_params={'os_username': os_username, 'os_password': os_password, 'os_project_id': os_project_id, 'os_auth_url': os_auth_url}) baremetal_factory.initialize(size=2) undercloud.write_instackenv(baremetal_factory) undercloud.ssh_pool.stop_all() print('done') exit(0) else: # Restoring the environment undercloud_ip = get_undercloud_ip(nova_api) undercloud = tripleohelper.ovb_undercloud.OVBUndercloud( key_filename=config['ssh']['private_key'], hostname=undercloud_ip) baremetal_factory = ovb_baremetal.BaremetalFactory( nova_api, neutron, keypair=config['provisioner']['keypair'], key_filename=config['ssh']['private_key'], security_groups=config['provisioner']['security-groups'], ) baremetal_factory.reload_environment(undercloud) undercloud.baremetal_factory = baremetal_factory if step == 'undercloud': if 'rhsm' in config: undercloud.rhsm_register({ 'login': config['rhsm']['login'], 'password': config['rhsm'].get('password'), 'pool_id': config['rhsm'].get('pool_id')}) undercloud.configure(config['undercloud']['repositories']) baremetal_factory.shutdown_nodes(undercloud) undercloud_config = provisioner.get('undercloud_config') if undercloud_config: undercloud_conf = open(undercloud_config, 'r').read() else: undercloud_conf = """ [DEFAULT] local_ip = 192.0.2.240/24 local_interface = eth1 local_mtu = 1400 dhcp_start = 192.0.2.50 dhcp_end = 192.0.2.70 undercloud_public_vip = 192.0.2.200 undercloud_admin_vip = 192.0.2.201 [auth] """ undercloud.create_file( 'undercloud.conf', undercloud_conf.format( undercloud_ip=undercloud.hostname), user='******') # Our OpenStack default tenant are below the 1500 limit, let's ensure we won't # have any frame truncated. undercloud.set_ctlplane_mtu(1400) undercloud.openstack_undercloud_install() undercloud.enable_neutron_hack(os_username, os_password, os_project_id, os_auth_url) undercloud.ssh_pool.stop_all() exit(0) if step == 'overcloud': if undercloud.run('test -f stackrc', user='******', ignore_error=True)[1] > 0: print('Run undercloud step first') exit(1) undercloud.fetch_overcloud_images(config.get('overcloud')) if undercloud.nova_version() < 14: undercloud.patch_ironic_ramdisk() undercloud.overcloud_image_upload() undercloud.load_instackenv() # the first as compute for node in baremetal_factory.nodes[:1]: undercloud.set_flavor(node, 'compute') # the rest is 'control' node for node in baremetal_factory.nodes[1:]: undercloud.set_flavor(node, 'control') # undercloud.start_overcloud_inspector() time.sleep(60) provisioner = config['provisioner'] templates = provisioner.get('heat_templates_dir') undercloud.manage_overcloud_templates(templates) deployment_file = provisioner.get('deployment_file') if deployment_file: remote_path = "/home/stack/%s" % os.path.basename(deployment_file) undercloud.send_file(deployment_file, remote_path, user='******', unix_mode=0o755) undercloud.start_overcloud_deploy(deploy_command=remote_path) else: undercloud.start_overcloud_deploy( control_scale=1, compute_scale=1, control_flavor='control', compute_flavor='compute', environments=[ '/home/stack/network-environment.yaml']) # create the public network undercloud.add_environment_file( user='******', filename='overcloudrc') undercloud.run( 'neutron net-create ext-net --shared --router:external=True', user='******') # NOTE(Goneri): this range is from TripleO default configuration. undercloud.run(( 'neutron subnet-create ext-net ' '10.0.0.0/24 ' '--name external ' '--allocation-pool start=10.0.0.4,end=10.0.0.250'), user='******') undercloud.ssh_pool.stop_all() exit(0)
def run_tests(context, undercloud_ip, key_filename, remoteci_id, user='******', stack_name='overcloud'): # Retrieve the certification_id data field. In order to run # the rhcert test suite if enabled. If absent set to empty string. data = remoteci.get_data( context, remoteci_id, ['certification_id']).json() certification_id = data and data.get('certification_id', '') # redirect the log messages to the DCI Control Server # https://github.com/shazow/urllib3/issues/523 requests.packages.urllib3.disable_warnings() dci_handler = DciHandler(context) logger = logging.getLogger('tripleohelper') logger.addHandler(dci_handler) undercloud = tripleohelper.undercloud.Undercloud( hostname=undercloud_ip, user=user, key_filename=key_filename) undercloud.create_stack_user() final_status = 'success' if undercloud.run( 'test -f stackrc', user='******', success_status=(0, 1,))[1] != 0: msg = 'undercloud deployment failure' jobstate.create(context, 'failure', msg, context.last_job_id) return jobstate.create( context, 'running', 'Running tripleo-stack-dump', context.last_job_id) push_stack_details(context, undercloud, stack_name=stack_name) rcfile = stack_name + 'rc' if undercloud.run( 'test -f ' + rcfile, user='******', success_status=(0, 1,))[1] != 0: msg = 'overcloud deployment failure' jobstate.create(context, 'failure', msg, context.last_job_id) return tests = job.list_tests(context, context.last_job_id).json()['tests'] try: for t in tests['tests']: if 'url' not in t['data']: continue jobstate.create( context, 'running', 'Running test ' + t['name'], context.last_job_id) url = t['data']['url'] undercloud.add_environment_file( user='******', filename=rcfile) undercloud.run('curl -O ' + url, user='******') undercloud.run(( 'DCI_CERTIFICATION_ID=%s ' 'DCI_REMOTECI_ID=%s ' 'DCI_JOB_ID=%s ' 'DCI_OVERCLOUD_STACK_NAME=%s ' 'bash -x run.sh') % ( certification_id, remoteci_id, context.last_job_id, stack_name), user='******') with undercloud.open('result.xml', user='******') as fd: file.create( context, t['name'], fd.read(), mime='application/junit', job_id=context.last_job_id) except Exception: msg = traceback.format_exc() final_status = 'failure' print(msg) else: msg = 'test(s) success' dci_handler.emit(None) jobstate.create(context, final_status, msg, context.last_job_id)
def cli(os_auth_url, os_username, os_password, os_project_id, config_file, step): config = yaml.load(config_file) logger.setup_logging(config_file=config.get('config_file')) undercloud = None baremetal_factory = None sess = os_utils.ks_session(os_auth_url, os_username, os_password, os_project_id) neutron = os_utils.build_neutron_client(sess) nova_api = os_utils.build_nova_api(sess) provisioner = config['provisioner'] print('step: %s' % step) if step == 'cleanup': purge_existing_ovb(nova_api, neutron) exit(0) if step == 'provisioning': purge_existing_ovb(nova_api, neutron) initialize_network(neutron) undercloud = ovb_undercloud.OVBUndercloud( key_filename=config['ssh']['private_key']) undercloud.start(nova_api=nova_api, neutron=neutron, provisioner=config['provisioner'], ip='192.0.2.240', floating_ip=config['undercloud'].get('floating_ip')) undercloud.create_stack_user() baremetal_factory = ovb_baremetal.BaremetalFactory( nova_api, neutron, keypair=config['provisioner']['keypair'], key_filename=config['ssh']['private_key'], security_groups=config['provisioner']['security-groups'], os_params={ 'os_username': os_username, 'os_password': os_password, 'os_project_id': os_project_id, 'os_auth_url': os_auth_url }) baremetal_factory.initialize(size=2) undercloud.write_instackenv(baremetal_factory) undercloud.ssh_pool.stop_all() print('done') exit(0) else: # Restoring the environment undercloud_ip = get_undercloud_ip(nova_api) undercloud = tripleohelper.ovb_undercloud.OVBUndercloud( key_filename=config['ssh']['private_key'], hostname=undercloud_ip) baremetal_factory = ovb_baremetal.BaremetalFactory( nova_api, neutron, keypair=config['provisioner']['keypair'], key_filename=config['ssh']['private_key'], security_groups=config['provisioner']['security-groups'], ) baremetal_factory.reload_environment(undercloud) undercloud.baremetal_factory = baremetal_factory if step == 'undercloud': if 'rhsm' in config: undercloud.rhsm_register({ 'login': config['rhsm']['login'], 'password': config['rhsm'].get('password'), 'pool_id': config['rhsm'].get('pool_id') }) undercloud.configure(config['undercloud']['repositories']) baremetal_factory.shutdown_nodes(undercloud) undercloud_config = provisioner.get('undercloud_config') if undercloud_config: undercloud_conf = open(undercloud_config, 'r').read() else: undercloud_conf = """ [DEFAULT] local_ip = 192.0.2.240/24 local_interface = eth1 local_mtu = 1400 dhcp_start = 192.0.2.50 dhcp_end = 192.0.2.70 undercloud_public_vip = 192.0.2.200 undercloud_admin_vip = 192.0.2.201 [auth] """ undercloud.create_file( 'undercloud.conf', undercloud_conf.format(undercloud_ip=undercloud.hostname), user='******') # Our OpenStack default tenant are below the 1500 limit, let's ensure we won't # have any frame truncated. undercloud.set_ctlplane_mtu(1400) undercloud.openstack_undercloud_install() undercloud.enable_neutron_hack(os_username, os_password, os_project_id, os_auth_url) undercloud.ssh_pool.stop_all() exit(0) if step == 'overcloud': if undercloud.run('test -f stackrc', user='******', ignore_error=True)[1] > 0: print('Run undercloud step first') exit(1) undercloud.fetch_overcloud_images(config.get('overcloud')) if undercloud.nova_version() < 14: undercloud.patch_ironic_ramdisk() undercloud.overcloud_image_upload() undercloud.load_instackenv() # the first as compute for node in baremetal_factory.nodes[:1]: undercloud.set_flavor(node, 'compute') # the rest is 'control' node for node in baremetal_factory.nodes[1:]: undercloud.set_flavor(node, 'control') # undercloud.start_overcloud_inspector() time.sleep(60) provisioner = config['provisioner'] templates = provisioner.get('heat_templates_dir') undercloud.manage_overcloud_templates(templates) deployment_file = provisioner.get('deployment_file') if deployment_file: remote_path = "/home/stack/%s" % os.path.basename(deployment_file) undercloud.send_file(deployment_file, remote_path, user='******', unix_mode=0o755) undercloud.start_overcloud_deploy(deploy_command=remote_path) else: undercloud.start_overcloud_deploy( control_scale=1, compute_scale=1, control_flavor='control', compute_flavor='compute', environments=['/home/stack/network-environment.yaml']) # create the public network undercloud.add_environment_file(user='******', filename='overcloudrc') undercloud.run( 'neutron net-create ext-net --shared --router:external=True', user='******') # NOTE(Goneri): this range is from TripleO default configuration. undercloud.run(('neutron subnet-create ext-net ' '10.0.0.0/24 ' '--name external ' '--allocation-pool start=10.0.0.4,end=10.0.0.250'), user='******') undercloud.ssh_pool.stop_all() exit(0)