Skip to content

Commit

Permalink
Implemented 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 Dec 17, 2019
1 parent 2991b0f commit 65baba4
Show file tree
Hide file tree
Showing 9 changed files with 474 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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

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 65baba4

Please sign in to comment.