Skip to content

Commit

Permalink
Add rpm-ostree tests (projectatomic#164)
Browse files Browse the repository at this point in the history
* Add rpm-ostree tests

Add a basic test suite for rpm-ostree.  There are still a few subcommands
that still need to be added to the test suite.  These tests assume
that the atomic host is provisioned with the latest version as it will
move between HEAD and HEAD-1.

Tests:
- Use rpm-ostree to deploy by version then rollback and delete rollback
- Use rpm-ostree to deploy by checksum then rollback and delete rollback
- Use rpm-ostree to deploy HEAD-1 then use cleanup pending deployments
- Simulate rpm-ostree upgrade then rebase to HEAD and delete rollback
- Simulate rpm-ostree upgrade with package install, then rebase to HEAD
  with an uninstall of the same package, then delete rollback
- Enable and validate client side initramfs generation then disable
  initramfs and cleanup deployments

* fixup! Add rpm-ostree tests

* fixup! Add rpm-ostree tests

* fixup! Add rpm-ostree tests

* fixup! Add rpm-ostree tests

* fixup! Add rpm-ostree tests
  • Loading branch information
mike-nguyen authored and Micah Abbott committed Jun 8, 2017
1 parent d52e9c9 commit 470968c
Show file tree
Hide file tree
Showing 8 changed files with 740 additions and 0 deletions.
24 changes: 24 additions & 0 deletions roles/rpm_ostree_rebase/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# vim: set ft=ansible:
#
# rpm-ostree rebase
# params:
# remote_name (required) name for remote
# remote_url (required) remote url
# refspec (required) remote refspec
- name: Fail if remote_name, remote_url, or refspec is not defined
fail:
msg: "remote_name, remote_url, or refspec is not defined"
when: remote_name is undefined or
remote_url is undefined or
refspec is undefined

- name: Add remote
command: ostree remote add --no-gpg-verify {{ remote_name }} {{ remote_url }}

- name: Rebase
command: rpm-ostree rebase {{ remote_name }}:{{ refspec }}
register: rebase
until: rebase.rc == 0
retries: 3
delay: 5
59 changes: 59 additions & 0 deletions roles/rpm_ostree_status_verify/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
# vim: set ft=ansible:
#
# This role validates rpm-ostree status output.
#
# Parameters:
# deployment (int) REQUIRED - index of deployment to verify
# expected (dict) REQUIRED - a dict of expected key/value pairs
# num_deployments (int) OPTIONAL - the number of deployments in output

- name: Fail if deployment or expected is undefined
fail:
msg: "deployment or expected is undefined"
when: expected is undefined or
deployment is undefined

- name: Get rpm-ostree status output
command: rpm-ostree status --json
register: ros_status

- name: Set json output
set_fact:
ros_json: "{{ ros_status.stdout | from_json }}"

- name: Set ros variable if deployment 0 is booted
set_fact:
ros_booted: "{{ ros_json['deployments'][0] }}"
ros_not_booted: "{{ ros_json['deployments'][1] if ros_json['deployments'][1] is defined else false }}"
when: ros_json['deployments'][0] is defined and ros_json['deployments'][0]['booted']

- name: Set ros variable if deployment 1 is booted
set_fact:
ros_booted: "{{ ros_json['deployments'][1] }}"
ros_not_booted: "{{ ros_json['deployments'][0] if ros_json['deployments'][0] is defined else false }}"
when: ros_json['deployments'][1] is defined and ros_json['deployments'][1]['booted']

- name: Set number of deployments
set_fact:
ros_num_deployments: "{{ ros_json['deployments'] | length }}"

- name: Verify number of deployments
fail:
msg: |
"Number of deployments is incorrect.
Expected: {{ num_deployments }}.
Actual {{ ros_num_deployments }}"
when: num_deployments is defined and {{ num_deployments | int }} != {{ ros_num_deployments | int }}

- name: Fail if deployment does not exist
fail:
msg: "deployment {{ deployment }} does not exist"
when: ros_json['deployments'][deployment] is undefined

- name: Fail if deployment {{ deployment }} values are incorrect
fail:
msg: "{{ item.key }} is incorrect or does not exist."
when: ros_json['deployments'][deployment][item.key] is undefined or
ros_json['deployments'][deployment][item.key] != item.value
with_dict: "{{ expected }}"
43 changes: 43 additions & 0 deletions tests/rpm-ostree/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
This playbook tests the basic rpm-ostree commands and options.

Core Functionality
- rpm-ostree compose
- rpm-ostree cleanup
- rpm-ostree db
- rpm-ostree deploy
- rpm-ostree rebase
- rpm-ostree rollback
- rpm-ostree status
- rpm-ostree upgrade
- rpm-ostree reload
- rpm-ostree initramfs

To be Covered
- rpm-ostree db

Covered In Another Test
- rpm-ostree install
- rpm-ostree uninstall

### Prerequisites
- Ansible version 2.2 (other versions are not supported)

- Configure subscription data (if used)

If running against a RHEL Atomic Host, you should provide subscription
data that can be used by `subscription-manager`. See
[roles/redhat_subscription/tasks/main.yml](roles/redhat_subscription/tasks/main.yml)
for additional details.

- Configure the required variables to your liking in [tests/rpm-ostree/vars.yml](vars.yml).

### Running the Playbook

To run the test, simply invoke as any other Ansible playbook:

```
$ ansible-playbook -i inventory tests/rpm-ostree/main.yml
```

*NOTE*: You are responsible for providing a host to run the test against and the
inventory file for that host.
1 change: 1 addition & 0 deletions tests/rpm-ostree/callback_plugins
15 changes: 15 additions & 0 deletions tests/rpm-ostree/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Test Coverage:
* rpm-ostree cleanup
* rpm-ostree deploy
* rpm-ostree rebase
* rpm-ostree rollback
* rpm-ostree status
* rpm-ostree upgrade
* rpm-ostree reload
* rpm-ostree initramfs

Not Covered:
* rpm-ostree compose
* rpm-ostree db
* rpm-ostree install
* rpm-ostree uninstall
Loading

0 comments on commit 470968c

Please sign in to comment.