def __init__(self, track, channel): arch = configbag.get_arch() cmd = "snapcraft list-revisions microk8s --arch {}".format( arch).split() revisions_list = check_output(cmd).decode("utf-8").split("\n") if track == "latest": channel_patern = " {}*".format(channel) else: channel_patern = " {}/{}*".format(track, channel) revision_info_str = None for revision in revisions_list: if channel_patern in revision: revision_info_str = revision if revision_info_str: # revision_info_str looks like this: # "180 2018-09-12T15:51:33Z amd64 v1.11.3 1.11/edge*" revision_info = revision_info_str.split() self.track = track self.channel = channel self.under_testing_channel = channel if "edge" in self.under_testing_channel: self.under_testing_channel = "{}/under-testing".format( self.under_testing_channel) self.revision = revision_info[0] self.version = revision_info[3] version_parts = self.version.split('.') self.major_minor_version = "{}.{}".format(version_parts[0], version_parts[1]) self.release_date = parser.parse(revision_info[1]) self.released = True else: self.released = False
def build_and_release(self, release=None, dry_run="no"): """ Build and release the snap from release. Args: release: what k8s version to package dry_run: if "no" do the actual release """ arch = configbag.get_arch() self.executor.remove_microk8s_directory() self.executor.clone_microk8s_repo() if release: if not release.startswith("v"): release = "v{}".format(release) self.executor.set_version_to_build(release) self.executor.build_snap() cmd = "rm -rf microk8s_latest_{}.snap".format(arch) run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT) self.executor.fetch_created_snap() target = "{}/{}".format(self.track, self.channel) cmd = "snapcraft push microk8s_latest_{}.snap --release {}".format(arch, target) if dry_run == "no": run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT) else: click.echo("DRY RUN - calling: {}".format(cmd)) cmd = "rm -rf microk8s_latest_{}.snap".format(arch) run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT)
def build_and_release(self, release=None, dry_run="no"): """ Build and release the snap from release. Args: release: what k8s version to package dry_run: if "no" do the actual release """ arch = configbag.get_arch() cmd = "rm -rf microk8s" cmd_array = self.cmd_array_to_run(cmd) check_call(cmd_array) cmd = "git clone https://github.com/ubuntu/microk8s" cmd_array = self.cmd_array_to_run(cmd) check_call(cmd_array) if release: if not release.startswith("v"): release = "v{}".format(release) cmd = "sed -i '/^set.*/a export KUBE_VERSION={}' microk8s/build-scripts/set-env-variables.sh".format( release ) if self.juju_controller: cmd_array = self.cmd_array_to_run(cmd) else: cmd_array = [ "sed", "-i", "/^set.*/a export KUBE_VERSION={}".format(release), "microk8s/build-scripts/set-env-variables.sh", ] check_call(cmd_array) cmd = "(cd microk8s; sudo /snap/bin/snapcraft cleanbuild)" cmd_array = self.cmd_array_to_run(cmd) check_call(cmd_array) cmd = "rm -rf microk8s_latest_{}.snap".format(arch) check_call(cmd.split()) if self.juju_controller: cmd = "juju scp -m {} {}:/var/lib/juju/agents/unit-ubuntu-0/charm/microk8s/microk8s_latest_{}.snap .".format( self.juju_controller, self.juju_unit, arch ) check_call(cmd.split()) else: cmd = "mv microk8s/microk8s_latest_{}.snap .".format(arch) check_call(cmd.split()) target = "{}/{}".format(self.track, self.channel) cmd = "snapcraft push microk8s_latest_{}.snap --release {}".format(arch, target) if dry_run == "no": check_call(cmd.split()) else: print("DRY RUN - calling: {}".format(cmd)) cmd = "rm -rf microk8s_latest_{}.snap".format(arch) check_call(cmd.split())
def __init__( self, track, channel, juju_unit=None, juju_controller=None, juju_model=None, testflinger_queue=None, ): arch = configbag.get_arch() channel_patern = "{}/{}*".format(track, channel) if juju_controller: click.echo("Using juju executor") self.executor = JujuExecutor(juju_unit, juju_controller, juju_model) elif testflinger_queue: click.echo("Using testflinger executor") self.executor = TestFlingerExecutor(testflinger_queue) else: click.echo("Using local executor") self.executor = LocalExecutor() self.track = track self.channel = channel revision_info_str = None cmd = "snapcraft list-revisions microk8s --arch {}".format(arch).split() click.echo("Callling {}".format(cmd)) revisions_list = run(cmd, stdout=PIPE, stderr=STDOUT) revisions_list = revisions_list.stdout.decode("utf-8").split("\n") click.echo("Got revisions list with size {}".format(len(revisions_list))) click.echo("Searching for {} in revisions list".format(channel_patern)) for revision in revisions_list: if channel_patern in revision: revision_info_str = revision if revision_info_str: # revision_info_str looks like this: # "180 2018-09-12T15:51:33Z amd64 v1.11.3 1.11/edge*" revision_info = revision_info_str.split() self.under_testing_channel = channel if "edge" in self.under_testing_channel: self.under_testing_channel = "{}/under-testing".format( self.under_testing_channel ) self.revision = revision_info[0] self.version = revision_info[3] version_parts = self.version.split(".") self.is_prerelease = False if not version_parts[2].isdigit(): self.is_prerelease = True self.major_minor_version = "{}.{}".format( version_parts[0], version_parts[1] ) self.release_date = parser.parse(revision_info[1]) self.released = True else: self.released = False
def fetch_created_snap(self, arch=None): if not arch: arch = configbag.get_arch() cmd = ( "juju scp -m {}:{} " "{}:/home/ubuntu/microk8s/microk8s_*_{}.snap microk8s_latest_{}.snap" .format(self.controller, self.model, self.unit, arch, arch)) try: run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT) except CalledProcessError as err: click.echo(err.output) raise err
def __init__(self, track, channel, juju_unit=None, juju_controller=None): arch = configbag.get_arch() cmd = "snapcraft list-revisions microk8s --arch {}".format( arch).split() revisions_list = run(cmd, stdout=PIPE, stderr=STDOUT) revisions_list = revisions_list.stdout.decode("utf-8").split("\n") if track == "latest": channel_patern = " {}*".format(channel) else: channel_patern = " {}/{}*".format(track, channel) self.juju_unit = juju_unit self.juju_controller = juju_controller self.track = track self.channel = channel revision_info_str = None for revision in revisions_list: if channel_patern in revision: revision_info_str = revision if revision_info_str: # revision_info_str looks like this: # "180 2018-09-12T15:51:33Z amd64 v1.11.3 1.11/edge*" revision_info = revision_info_str.split() self.under_testing_channel = channel if "edge" in self.under_testing_channel: self.under_testing_channel = "{}/under-testing".format( self.under_testing_channel) self.revision = revision_info[0] self.version = revision_info[3] version_parts = self.version.split(".") self.is_prerelease = False if not version_parts[2].isdigit(): self.is_prerelease = True self.major_minor_version = "{}.{}".format(version_parts[0], version_parts[1]) self.release_date = parser.parse(revision_info[1]) self.released = True else: self.released = False
def fetch_created_snap(self, arch=None): if not arch: arch = configbag.get_arch() cmd = "mv microk8s/microk8s_*_{0}.snap microk8s_latest_{0}.snap".format( arch) Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
def build_and_release(self, release=None, dry_run="no"): """ Build and release the snap from release. Args: release: what k8s version to package dry_run: if "no" do the actual release """ arch = configbag.get_arch() cmd = "rm -rf microk8s" cmd_array = self.cmd_array_to_run(cmd) for line in sh2.env(cmd_array): click.echo(line.strip()) cmd = "git clone https://github.com/ubuntu/microk8s" cmd_array = self.cmd_array_to_run(cmd) for line in sh2.env(cmd_array): click.echo(line.strip()) if release: if not release.startswith("v"): release = "v{}".format(release) cmd = "sed -i '/^set.*/a export KUBE_VERSION={}' microk8s/build-scripts/set-env-variables.sh".format( release) if self.juju_controller: cmd_array = self.cmd_array_to_run(cmd) else: cmd_array = [ "sed", "-i", "/^set.*/a export KUBE_VERSION={}".format(release), "microk8s/build-scripts/set-env-variables.sh", ] for line in sh2.env(cmd_array): click.echo(line.strip()) cmd = "(cd microk8s; pwd; sudo /snap/bin/snapcraft --use-lxd)" cmd_array = self.cmd_array_to_run(cmd) for line in sh2.env(cmd_array): click.echo(line.strip()) cmd = "rm -rf microk8s_latest_{}.snap".format(arch) run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT) if self.juju_controller: _model = os.environ.get("JUJU_MODEL") cmd = ( "juju scp -m {}:{} " "{}:/home/ubuntu/microk8s/microk8s_*_{}.snap microk8s_latest_{}.snap" .format(self.juju_controller, _model, self.juju_unit, arch, arch)) try: run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT) except CalledProcessError as err: click.echo(err.output) raise err else: cmd = "mv microk8s/microk8s_*_{}.snap microk8s_latest_{}.snap".format( arch, arch) run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT) target = "{}/{}".format(self.track, self.channel) cmd = "snapcraft push microk8s_latest_{}.snap --release {}".format( arch, target) if dry_run == "no": run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT) else: click.echo("DRY RUN - calling: {}".format(cmd)) cmd = "rm -rf microk8s_latest_{}.snap".format(arch) run(cmd.split(), check=True, stdout=PIPE, stderr=STDOUT)