def build_debs_from_dev_instance(context: Context, series: str) -> "List[str]": """Create a development instance, instal build dependencies and build debs Will stop the development instance after deb build succeeds. :return: A list of paths to applicable deb files published. """ time_suffix = datetime.datetime.now().strftime("%s%f") debs_path = get_debs_path_from_series(series, context) if debs_path: if os.path.isdir(debs_path): deb_paths = [ os.path.join(debs_path, deb_file) for deb_file in os.listdir(debs_path) ] else: print( "--- Launching vm to build ubuntu-advantage*debs from local source" ) if context.config.cloud_manager: cloud_manager = context.config.cloud_manager inst = cloud_manager.launch( series=series, user_data=USERDATA_INSTALL_DAILY_PRO_UATOOLS) def cleanup_instance() -> None: if not context.config.destroy_instances: print("--- Leaving instance running: {}".format(inst.id)) else: inst.delete(wait=False) build_container_name = cloud_manager.get_instance_id(inst) else: build_container_name = ("behave-image-pre-build-%s-" % series + time_suffix) is_vm = bool(context.config.machine_type == "lxd.vm") if is_vm and series == "xenial": # FIXME: use lxd custom cloud images which containt HWE kernel # for vhost-vsock support lxc_ubuntu_series = "images:ubuntu/16.04/cloud" else: lxc_ubuntu_series = "ubuntu-daily:%s" % series launch_lxd_container( context, series=series, image_name=lxc_ubuntu_series, container_name=build_container_name, is_vm=is_vm, ) with emit_spinner_on_travis("Building debs from local source... "): deb_paths = build_debs( build_container_name, output_deb_dir=LOCAL_BUILD_ARTIFACTS_DIR, cloud_api=context.config.cloud_api, ) if "pro" in context.config.machine_type: return deb_paths # Redact ubuntu-advantage-pro deb as inapplicable return [deb_path for deb_path in deb_paths if "pro" not in deb_path]
def create_uat_lxd_image(context: Context, series: str) -> None: """Create a given series lxd image with ubuntu-advantage-tools installed This will launch a container, install ubuntu-advantage-tools, and publish the image. The image's name is stored in context.series_image_name for use within step code. :param context: A `behave.runner.Context`; this will have `series.image_name` set on it. :param series: A string representing the series name to create """ if series in context.reuse_container: print( "\n Reusing the existing container: ", context.reuse_container[series], ) return now = datetime.datetime.now() context.series_image_name[ series ] = "behave-image-%s-" % series + now.strftime("%s%f") build_container_name = "behave-image-build-%s-" % series + now.strftime( "%s%f" ) ubuntu_series = "ubuntu-daily:%s" % series launch_lxd_container(context, ubuntu_series, build_container_name) _install_uat_in_container(build_container_name) _capture_container_as_image( build_container_name, context.series_image_name[series] )
def create_trusty_uat_lxd_image(context: Context) -> None: """Create a trusty lxd image with ubuntu-advantage-tools installed This will launch a container, install ubuntu-advantage-tools, and publish the image. The image's name is stored in context.image_name for use within step code. :param context: A `behave.runner.Context`; this will have `image_name` set on it. """ def image_cleanup() -> None: if context.config.image_clean: subprocess.run(["lxc", "image", "delete", context.image_name]) else: print("Image cleanup disabled, not deleting:", context.image_name) if context.reuse_container: print(" Reusing the existent container: ", context.reuse_container) else: now = datetime.datetime.now() context.image_name = "behave-image-" + now.strftime("%s%f") build_container_name = "behave-image-build-" + now.strftime("%s%f") launch_lxd_container(context, "ubuntu:trusty", build_container_name) _install_uat_in_container(build_container_name) _capture_container_as_image(build_container_name, context.image_name) context.add_cleanup(image_cleanup)
def given_a_lxd_container(context, series): if series in context.reuse_container: context.container_name = context.reuse_container[series] else: now = datetime.datetime.now() context.container_name = (CONTAINER_PREFIX + series + now.strftime("-%s%f")) launch_lxd_container(context, context.series_image_name[series], context.container_name)
def given_a_trusty_lxd_container(context): if context.reuse_container: context.container_name = context.reuse_container else: now = datetime.datetime.now() context.container_name = CONTAINER_PREFIX + now.strftime("%s%f") launch_lxd_container( context, context.image_name, context.container_name )
def given_a_machine(context, series): filter_series = context.config.filter_series if filter_series and series not in filter_series: context.scenario.skip( reason=( "Skipping scenario outline series {series}." " Cmdline provided @series tags: {cmdline_series}".format( series=series, cmdline_series=filter_series ) ) ) return if series in context.reuse_container: context.container_name = context.reuse_container[series] if "pro" in context.config.machine_type: context.instance = context.config.cloud_api.get_instance( context.container_name ) return if series not in context.series_image_name: with emit_spinner_on_travis(): create_uat_image(context, series) if context.config.cloud_manager: context.instance = context.config.cloud_manager.launch( series=series, image_name=context.series_image_name[series] ) context.container_name = context.config.cloud_manager.get_instance_id( context.instance ) else: is_vm = bool(context.config.machine_type == "lxd.vm") now = datetime.datetime.now() vm_prefix = "vm-" if is_vm else "" context.container_name = ( CONTAINER_PREFIX + vm_prefix + series + now.strftime("-%s%f") ) launch_lxd_container( context, series=series, image_name=context.series_image_name[series], container_name=context.container_name, is_vm=is_vm, )
def create_uat_lxd_image(context: Context, series: str) -> None: """Create a given series lxd image with ubuntu-advantage-tools installed This will launch a container, install ubuntu-advantage-tools, and publish the image. The image's name is stored in context.series_image_name for use within step code. :param context: A `behave.runner.Context`; this will have `series.image_name` set on it. :param series: A string representing the series name to create """ if series in context.reuse_container: print( "\n Reusing the existing container: ", context.reuse_container[series], ) return now = datetime.datetime.now() ubuntu_series = "ubuntu-daily:%s" % series deb_file = None if context.config.build_pr: # create a dirty development image which installs build depends deb_file = PR_DEB_FILE build_container_name = ("behave-image-pre-build-%s-" % series + now.strftime("%s%f")) launch_lxd_container(context, ubuntu_series, build_container_name) lxc_build_deb(build_container_name, output_deb_file=deb_file) build_container_name = "behave-image-build-%s-" % series + now.strftime( "%s%f") launch_lxd_container(context, ubuntu_series, build_container_name) # if build_pr it will install new built .deb _install_uat_in_container(build_container_name, deb_file=deb_file) context.series_image_name[ series] = "behave-image-%s-" % series + now.strftime("%s%f") _capture_container_as_image(build_container_name, context.series_image_name[series])
def create_uat_image(context: Context, series: str) -> None: """Create a given series lxd image with ubuntu-advantage-tools installed This will launch a container, install ubuntu-advantage-tools, and publish the image. The image's name is stored in context.series_image_name for use within step code. :param context: A `behave.runner.Context`; this will have `series.image_name` set on it. :param series: A string representing the series name to create """ if series in context.reuse_container: print( "\n Reusing the existing container: ", context.reuse_container[series], ) return time_suffix = datetime.datetime.now().strftime("%s%f") deb_paths = [] if context.config.build_pr: deb_paths = build_debs_from_dev_instance(context, series) print( "--- Launching VM to create a base image with updated ubuntu-advantage" ) if context.config.cloud_manager: inst = context.config.cloud_manager.launch( series=series, user_data=USERDATA_INSTALL_DAILY_PRO_UATOOLS) build_container_name = context.config.cloud_manager.get_instance_id( inst) else: is_vm = bool(context.config.machine_type == "lxd.vm") build_container_name = "behave-image-build-%s-%s" % ( "-vm" if is_vm else "", series + time_suffix, ) if is_vm and series == "xenial": # FIXME: use lxd custom cloud images which containt HWE kernel for # vhost-vsock support lxc_ubuntu_series = "images:ubuntu/16.04/cloud" else: lxc_ubuntu_series = "ubuntu-daily:%s" % series launch_lxd_container( context, series=series, image_name=lxc_ubuntu_series, container_name=build_container_name, is_vm=is_vm, ) _install_uat_in_container( build_container_name, deb_paths=deb_paths, cloud_api=context.config.cloud_api, ) image_name = _capture_container_as_image( build_container_name, image_name="behave-image-%s-" % series + time_suffix, cloud_api=context.config.cloud_api, ) context.series_image_name[series] = image_name