Skip to content

Commit

Permalink
Implement mixer reset command
Browse files Browse the repository at this point in the history
It reverts the mix to a previous version in case of a build failure or in case
the user wants to roll back to a specific version.
By default, the command will  bring back the mix to the same state
it have when it last build a successful mix.
This value can be overridden if a `--to` flag is provided with a version number.
The command will not be destructive unless a `--clean` flag is provided specified.
If so, mixer will delete all files associated with versions that are bigger than the one provided.
If not, only the values of the state files will change, but the files will be kept.

Signed-off-by: Ashlesha Atrey <[email protected]>
  • Loading branch information
ashleshaAtrey committed Jan 27, 2020
1 parent 3df9e11 commit c2ca375
Show file tree
Hide file tree
Showing 11 changed files with 488 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ MANPAGES = \
docs/mixer.init.1 \
docs/mixer.repo.1 \
docs/mixer.versions.1 \
docs/mixin.1
docs/mixin.1 \
docs/mixer.reset.1

man: $(MANPAGES)

Expand Down
10 changes: 10 additions & 0 deletions bat/tests/reset-command/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: check clean

check:
bats ./run.bats

CLEANDIRS = ./update ./test-chroot ./logs ./.repos ./bundles ./update ./mix-bundles ./clr-bundles ./local-yum ./results ./repodata ./local-rpms ./upstream-bundles ./local-bundles
CLEANFILES = ./*.log ./run.bats.trs ./yum.conf.in ./builder.conf ./mixer.state ./.{c,m}* *.pem .yum-mix.conf mixversion upstreamurl upstreamversion mixbundles
clean:
sudo rm -rf $(CLEANDIRS) $(CLEANFILES)

7 changes: 7 additions & 0 deletions bat/tests/reset-command/description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
reset
====================
This test attempts to create multiple mixes of different versions
in different format. It then tries to revert the mix to a previous stable
version. If clean flag is set, mixer will delete all files associated with
versions that are bigger than the one provided.

34 changes: 34 additions & 0 deletions bat/tests/reset-command/run.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bats

# shared test functions
load ../../lib/mixerlib

setup() {
global_setup
}

@test "reset" {
mixer-init-stripped-down latest 10
sudo mixer build all --format 1 --native
mixer-versions-update 20 latest
sudo mixer build all --format 2 --native
mixer-versions-update 30 latest
sudo mixer build all --format 3 --native
#check LAST_VER and PREVIOUS_MIX_VERSION match
test $(< update/image/LAST_VER) -eq 30
test $(sed -n 's/[ ]*PREVIOUS_MIX_VERSION[ ="]*\([0-9]\+\)[ "]*/\1/p' mixer.state) -eq 20
sudo mixer reset --to 20
#check LAST_VER and PREVIOUS_MIX_VERSION match
test $(< update/image/LAST_VER) -eq 20
test $(sed -n 's/[ ]*PREVIOUS_MIX_VERSION[ ="]*\([0-9]\+\)[ "]*/\1/p' mixer.state) -eq 10
test -d "./update/www/30"
test -d "./update/image/30"
sudo mixer reset --to 10 --clean
#check LAST_VER and PREVIOUS_MIX_VERSION match
test $(< update/image/LAST_VER) -eq 10
test $(sed -n 's/[ ]*PREVIOUS_MIX_VERSION[ ="]*\([0-9]\+\)[ "]*/\1/p' mixer.state) -eq 0
test ! -d "./update/www/20"
test ! -d "./update/image/30"
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80

8 changes: 4 additions & 4 deletions builder/build_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (b *Builder) mcaPkgInfo(manifests []*swupd.Manifest, version, downloadRetri
repoURIs := make(map[string]string)

// Download RPMs from correct upstream version
upstreamVer, err := b.getLocalUpstreamVersion(strconv.Itoa(version))
upstreamVer, err := b.GetLocalUpstreamVersion(strconv.Itoa(version))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1126,7 +1126,7 @@ func checkMcaFbErrors(b *Builder, diffErrors []string, fromVer, toVer int) ([]st
// isPlus10Version determines whether the version is the last version in a format.
func (b *Builder) isPlus10Version(ver int) (bool, error) {
verStr := strconv.Itoa(ver)
format, err := b.getFormatForVersion(verStr)
format, err := b.GetFormatForVersion(verStr)
if err != nil {
return false, err
}
Expand All @@ -1146,11 +1146,11 @@ func (b *Builder) isPlus10Version(ver int) (bool, error) {

// checkFormatsMatch determines whether two versions are in the same format.
func (b *Builder) checkFormatsMatch(fromVer, toVer int) (bool, error) {
fromFormat, err := b.getFormatForVersion(strconv.Itoa(fromVer))
fromFormat, err := b.GetFormatForVersion(strconv.Itoa(fromVer))
if err != nil {
return false, err
}
toFormat, err := b.getFormatForVersion(strconv.Itoa(toVer))
toFormat, err := b.GetFormatForVersion(strconv.Itoa(toVer))
if err != nil {
return false, err
}
Expand Down
7 changes: 4 additions & 3 deletions builder/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (b *Builder) getLastBuildUpstreamVersion() (string, error) {
return strings.TrimSpace(string(lastVer)), nil
}

// getFormatForVersion returns the format for the provided local version
func (b *Builder) getFormatForVersion(version string) (string, error) {
// GetFormatForVersion returns the format for the provided local version
func (b *Builder) GetFormatForVersion(version string) (string, error) {
var format []byte
var err error

Expand All @@ -98,7 +98,8 @@ func (b *Builder) getLatestForFormat(format string) (string, error) {
return strings.TrimSpace(string(lastVer)), nil
}

func (b *Builder) getLocalUpstreamVersion(version string) (string, error) {
// GetLocalUpstreamVersion returns the upstream version for the provided version
func (b *Builder) GetLocalUpstreamVersion(version string) (string, error) {
var localUpstreamVer []byte
var err error

Expand Down
14 changes: 14 additions & 0 deletions docs/mixer.1
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ upstream available. Also allows the user to update mix and upstream
versions. See \fBmixer.versions\fP(1) for more details.
.UNINDENT
.UNINDENT
.sp
\fBreset\fP
.INDENT 0.0
.INDENT 3.5
Reverts a mix state to the end of the last build or to the end
of a given version build if one is provided. By default, the value
of PREVIOUS_MIX_VERSION in mixer.state will be used to define the
last build. This command can be used to roll back the mixer state
in case of a build failure or in case the user wants to roll back
to a previous version. See \fBmixer.reset\fP(1) for more details.
.UNINDENT
.UNINDENT
.SH FILES
.sp
\fI<mixer/workspace>/builder.conf\fP
Expand Down Expand Up @@ -184,6 +196,8 @@ On success, 0 is returned. A non\-zero return code indicates a failure.
.IP \(bu 2
\fBmixer.versions\fP(1)
.IP \(bu 2
\fBmixer.reset\fP(1)
.IP \(bu 2
\fBswupd\fP(1)
.IP \(bu 2
\fBos\-format\fP(7)
Expand Down
10 changes: 10 additions & 0 deletions docs/mixer.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ SUBCOMMANDS
upstream available. Also allows the user to update mix and upstream
versions. See ``mixer.versions``\(1) for more details.

``reset``

Reverts a mix state to the end of the last build or to the end
of a given version build if one is provided. By default, the value
of PREVIOUS_MIX_VERSION in mixer.state will be used to define the
last build. This command can be used to roll back the mixer state
in case of a build failure or in case the user wants to roll back
to a previous version. See ``mixer.reset``\(1) for more details.


FILES
=====
Expand Down Expand Up @@ -142,6 +151,7 @@ SEE ALSO
* ``mixer.init``\(1)
* ``mixer.repo``\(1)
* ``mixer.versions``\(1)
* ``mixer.reset``\(1)
* ``swupd``\(1)
* ``os-format``\(7)
* https://github.com/clearlinux/mixer-tools
Expand Down
73 changes: 73 additions & 0 deletions docs/mixer.reset.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.\" Man page generated from reStructuredText.
.
.TH MIXER.RESET 1 "" "" ""
.SH NAME
mixer.reset \- Reset mixer to a given or previous version
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.SH SYNOPSIS
.sp
\fBmixer reset [flags]\fP
.SH DESCRIPTION
.sp
Reverts a mix state to the end of the last build or to the end
of a given version build if one is provided. By default, the value
of PREVIOUS_MIX_VERSION in mixer.state will be used to define the
last build. This command can be used to roll back the mixer state
in case of a build failure or in case the user wants to roll back
to a previous version.
.SH OPTIONS
.sp
In addition to the globally recognized \fBmixer\fP flags (see \fBmixer\fP(1) for
more details), the following options are recognized.
.INDENT 0.0
.IP \(bu 2
\fB\-\-to\fP
.sp
Reverts the mix to the version provided by the flag
.IP \(bu 2
\fB\-\-clean\fP
.sp
Delete all files associated with versions that are bigger than the one provided.
.IP \(bu 2
\fB\-h, \-\-help\fP
.sp
Display \fBreset\fP help information and exit.
.UNINDENT
.SH EXIT STATUS
.sp
On success, 0 is returned. A non\-zero return code indicates a failure.
.SS SEE ALSO
.INDENT 0.0
.IP \(bu 2
\fBmixer\fP(1)
.UNINDENT
.SH COPYRIGHT
(C) 2019 Intel Corporation, CC-BY-SA-3.0
.\" Generated by docutils manpage writer.
.
56 changes: 56 additions & 0 deletions docs/mixer.reset.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
===========
mixer.reset
===========

------------------------------------------
Reset mixer to a given or previous version
------------------------------------------

:Copyright: \(C) 2019 Intel Corporation, CC-BY-SA-3.0
:Manual section: 1


SYNOPSIS
========

``mixer reset [flags]``


DESCRIPTION
===========

Reverts a mix state to the end of the last build or to the end
of a given version build if one is provided. By default, the value
of PREVIOUS_MIX_VERSION in mixer.state will be used to define the
last build. This command can be used to roll back the mixer state
in case of a build failure or in case the user wants to roll back
to a previous version.

OPTIONS
=======

In addition to the globally recognized ``mixer`` flags (see ``mixer``\(1) for
more details), the following options are recognized.

- ``--to``

Reverts the mix to the version provided by the flag

- ``--clean``

Delete all files associated with versions that are bigger than the one provided.

- ``-h, --help``

Display ``reset`` help information and exit.


EXIT STATUS
===========

On success, 0 is returned. A non-zero return code indicates a failure.

SEE ALSO
--------

* ``mixer``\(1)
Loading

0 comments on commit c2ca375

Please sign in to comment.