Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Add rpm-ostree tests#164

Merged
miabbott merged 6 commits intoprojectatomic:masterfrom
mike-nguyen:ros
Jun 8, 2017
Merged

Add rpm-ostree tests#164
miabbott merged 6 commits intoprojectatomic:masterfrom
mike-nguyen:ros

Conversation

@mike-nguyen
Copy link
Copy Markdown
Collaborator

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

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
@mike-nguyen
Copy link
Copy Markdown
Collaborator Author

I tested on CAHC, RHELAH 7.3.5, and Fedora 26. The rpm-ostree version installed must support the --install and --uninstall flags so CentOS AH may not have it yet.

Copy link
Copy Markdown
Contributor

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really nice overall!

There's definitely some overlap with the rpm-ostree vmcheck testsuite, which reminds me of the thoughts in #74. Though this is clearly a net add in absence of that. (Maybe this can be a faster rpm-ostree sanity check and vmcheck can be the more comprehensive, lower down the pipe test that takes much longer).


Covered In Another Test
- rpm-ostree install
- rpm-ostree uninstall
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, so should install and uninstall be removed from the list just before then?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package layering feature has a separate test suite already in atomic-host-tests. The install/uninstall below is the package layering as options to deploy, upgrade, and rebase

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just read this again. I will remove it form the readme.

Comment thread tests/rpm-ostree/main.yml Outdated
delay: 5

- name: Get HEAD-1 version
shell: ostree log {{ refspec.stdout }} | grep Version | tail -1 | cut -d' ' -f2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get it straight from ostree without parsing!

ostree show $revision --print-metadata-key version

Comment thread tests/rpm-ostree/main.yml Outdated
head_version: "{{ ross_json['deployments'][0]['version'] if ross_json['deployments'][0]['booted'] else ross_json['deployments'][1]['version'] }}"

- name: Pull last two commits
command: ostree pull --subpath /usr/share/rpm --depth=1 {{ refspec.stdout }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for puling /usr/share/rpm? Can't find where we're querying the rpmdb lower down. Seems like we can just use --commit-metadata-only?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We switched to this for CAHC and FAHC. I was away when this change happened so I don't know the specifics. It has something to do with commit history on the continuous streams. @miabbott do you know offhand why we moved to this instead of commit-metadata-only?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we started doing this in our deployment playbooks/ jobs:

commit 7857fe3
Author: Micah Abbott <miabbott@redhat.com>
Date:   Wed Oct 12 11:01:25 2016 -0400

    ans_atomic_info: fetch commit and file/RPM data
    
    This changes the playbook to pull the file/RPM data for use in determining
    the the package differences between HEAD^ and HEAD of the stream being
    tested.
    
    We had avoided doing this in the past because an `ostree pull
    --commit-metatdata-only` of the CAHC stream would fetch the deltas
    being generated between the two commits.  Thus, the `rpm-ostree db
    diff` would return the desired results.
...

I think in this instance we are safe just pulling the commit metadata

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I made the changes to commit metadata

Comment thread tests/rpm-ostree/main.yml Outdated

tasks:
- name: Get current refspec
shell: cat $(ostree admin --print-current-dir).origin | grep refspec | cut -d= -f2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get that from the json too, though right? It's the origin key.

Comment thread tests/rpm-ostree/main.yml
command: ostree refs --create local-branch {{ head_csum }}

- name: Update origin file
command: sed -i 's/^\(.*refspec\)=.*$/\1=local-branch/g' {{ current_dir.stdout }}.origin
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be safer to do an rpm-ostree reload here after this just for good practice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the rpm-ostree reload then verify the rpm-ostree status output which is a test for rpm-ostree reload.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add the reload test, or do you mean to add it in a separate PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlebon I ran into an error running rpm-ostree reload yesterday. I was going to ask you about it today since you were in training but now I can't reproduce it. I've added the reload after modifying the origin file.

Comment thread tests/rpm-ostree/main.yml Outdated

- name: Convert to json
set_fact:
ross_json: "{{ ros_status.stdout | from_json }}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we could factor these two tasks into e.g. an include. IIRC, we should still be able to access ross_json afterwards, I think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works. There was already the rpm_ostree_status role that converts to json then sets ross_json and also sets booted and unbooted to the proper deployment.

Comment thread tests/rpm-ostree/main.yml Outdated
#
#####################################################################################

- name: rpm-ostree - upgrade and rebase + install and uninstall
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this needs to be changed? :)

Comment thread tests/rpm-ostree/main.yml Outdated
- name: Fail if contents of initramfs is incorrect
fail:
msg: "Expected /etc/rpmostree-initramfs-testing-file in initramfs"
when: "'/etc/rpmostree-initramfs-testing-file' not in lsinitrd.stdout"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a subtle issue with this. The output of lsinitrd also prints out the arguments that were used to create the initramfs, which I suspect why this is matching. (The actual file listings don't have a leading / in their filenames).

Maybe a better check here is lsinitrd $initrd -f /my/file and checking that e.g. This is the contents of my file is in the output?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlebon when I run lsinitrd $initrd -f /my/file it produces no file. Am I running the command right?

[root@fedora ~]# ll
total 16
-rw-------. 1 root root 5538 Apr 19 13:13 anaconda-ks.cfg
-rw-------. 1 root root 5196 Apr 19 13:13 original-ks.cfg
[root@fedora ~]# lsinitrd /boot/ostree/fedora-atomic-58da926b4642c6974a8b357b074f3ad3cf168163fb28c42cf3a010eda0ab4b84/initramfs-4.11.0-0.rc6.git0.1.fc26.x86_64.img -f ./myfile.txt
[root@fedora ~]# ll
total 16
-rw-------. 1 root root 5538 Apr 19 13:13 anaconda-ks.cfg
-rw-------. 1 root root 5196 Apr 19 13:13 original-ks.cfg
[root@fedora ~]# lsinitrd /boot/ostree/fedora-atomic-58da926b4642c6974a8b357b074f3ad3cf168163fb28c42cf3a010eda0ab4b84/initramfs-4.11.0-0.rc6.git0.1.fc26.x86_64.img 
Image: /boot/ostree/fedora-atomic-58da926b4642c6974a8b357b074f3ad3cf168163fb28c42cf3a010eda0ab4b84/initramfs-4.11.0-0.rc6.git0.1.fc26.x86_64.img: 49M
========================================================================
Early CPIO image
========================================================================
drwxr-xr-x   3 root     root            0 Jan  1  1970 .
-rw-r--r--   1 root     root            2 Jan  1  1970 early_cpio
drwxr-xr-x   3 root     root            0 Jan  1  1970 kernel
drwxr-xr-x   3 root     root            0 Jan  1  1970 kernel/x86
drwxr-xr-x   2 root     root            0 Jan  1  1970 kernel/x86/microcode
-rw-r--r--   1 root     root        24070 Jan  1  1970 kernel/x86/microcode/AuthenticAMD.bin
========================================================================
Version: dracut-044-178.fc26

Arguments: --reproducible --gzip -v --add 'ostree' --tmpdir '/tmp' -f --no-hostonly --add 'iscsi' --kver '4.11.0-0.rc6.git0.1.fc26.x86_64' --reproducible --gzip -v --add 'ostree' --tmpdir '/tmp' -f -I '/etc/rpmostree-initramfs-testing-file' --kver '4.11.0-0.rc6.git0.1.fc26.x86_64'
..snip...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, sorry, I should have written it as -f $path_to_my_file. I.e. the same path you included earlier. E.g.:

# echo "barbaz" > /etc/foo.conf
# rpm-ostree initramfs --enable --arg="-I" --arg="/etc/foo.conf"
# lsinitrd /boot/ostree/fedora-atomic-73577e678e475e49881041c3b7c747c9665b95a645cc2aef85e6678c62a5ce35/initramfs-4.11.3-200.fc25.x86_64.img -f /etc/foo.conf
barbaz

Comment thread tests/rpm-ostree/main.yml Outdated

tasks:
- name: Get current refspec
shell: cat $(ostree admin --print-current-dir).origin | grep refspec | cut -d= -f2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get this from the JSON output of rpm-ostree status? It looks like it may be the origin value:

# rpm-ostree status --json | python -m json.tool
{
    "deployments": [
        {
            "booted": true,
            "checksum": "0ccf9138962e5c2c3794969a228e751d13bb780f5b0a1f15f4a9649df06ba80a",
            "gpg-enabled": false,
            "id": "rhel-atomic-host-0ccf9138962e5c2c3794969a228e751d13bb780f5b0a1f15f4a9649df06ba80a.0",
            "origin": "rhel-atomic-host:rhel-atomic-host/7/x86_64/standard",
            "osname": "rhel-atomic-host",
            "packages": [],
            "regenerate-initramfs": false,
            "requested-local-packages": [],
            "requested-packages": [],
            "serial": 0,
            "timestamp": 1495490444,
            "unlocked": "none",
            "version": "7.3.5"
        }
    ],
    "transaction": null
}

@jlebon Can you confirm this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's correct! I made the same suggestion a bit lower down on another instance of this.

Comment thread tests/rpm-ostree/main.yml Outdated
delay: 5

- name: Get HEAD-1 checksum
shell: ostree log {{ refspec.stdout }} | grep ^commit | tail -1 | cut -d' ' -f2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get this with ostree rev-parse $refspec^. Like this:

# ostree rev-parse rhel-atomic-host/7/x86_64/standard^
d6c7a5639cdeb6c21cf40d80259d516d047176e35411c8684cae40a93eedbed0

# remote_name (required) name for remote
# remote_url (required) remote url
# refspec (required) remote refspec

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add a fail statement here if the parameters aren't defined?

@miabbott
Copy link
Copy Markdown
Collaborator

miabbott commented Jun 2, 2017

This is a good set of tests. I'd echo what has been said already that if we could make a role that basically generates a variable containing the JSON of rpm-ostree status, it would cleanup the code duplication.

@mike-nguyen
Copy link
Copy Markdown
Collaborator Author

Pushed fixup with the changes suggested.

Comment thread tests/rpm-ostree/main.yml Outdated
shell: ostree show $(ostree rev-parse {{ refspec }}^) --print-metadata-key version | tr -d \'
register: hmo_version

- name: Deploy version {{ hmo_version.stdout }}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - I don't think variable substitution happens for the name: statements

Copy link
Copy Markdown
Collaborator Author

@mike-nguyen mike-nguyen Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it does although I have seen instances when it doesn't (possibly in loops?). Seems like it only substitutes for the first instance if running against two hosts so I'll just remove it and add a generic message.

TASK [Deploy version 7.2017.383] ***********************************************
changed: [fedora] => {
    "attempts": 1, 
    "changed": true, 
    "cmd": [
        "rpm-ostree", 
        "deploy", 
        "26.55"
    ], 
    "delta": "0:00:32.515279", 
    "end": "2017-06-06 14:46:03.710649", 
    "rc": 0, 
    "start": "2017-06-06 14:45:31.195370", 
    "warnings": []
}

Comment thread tests/rpm-ostree/main.yml
- include: ../../common/ans_reboot.yml

# verify version in deployment 0
- include: roles/rpm_ostree_status_verify/tasks/main.yml
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to mix include vs. include_role in this test?

Copy link
Copy Markdown
Collaborator Author

@mike-nguyen mike-nguyen Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was kind of all over the place with the include vs include_role. I was trying to use include_role in as many places as possible because it takes out the relative path. The particular instances I did not use include_role was:

  1. ans_reboot.yml isn't in a roles directory so it needs to be included
  2. variables not being passed properly using include_role. I think cevich mentioned something along the lines of this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner if you could stick to one, but I won't hold up merging

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will change it to all includes for consistency

msg: "deployment {{ deployment }} does not exist"
when: ros_json['deployments'][deployment] is undefined

- name: Fail if deployment {{ deployment }} values are incorrect
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit confused why you used a dict here, but seeing it used in practice in the main test file made me understand.

Great idea and very flexible!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original implementation had dynamically named variables based on the rpm-ostree status json keys. The problem was that certain properties are displayed based on some rpm-ostree actions. If an action is undone, sometimes that property would disappear from the output but the variable would persist and cause some confusion validating property values.

Comment thread tests/rpm-ostree/main.yml
tasks:
- include: roles/rpm_ostree_status/tasks/main.yml

- name: Set current version and refspec
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to stick a comment here explaining that ros_booted comes from the rpm_ostree_status role that was included above.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment

Comment thread tests/rpm-ostree/main.yml
- name: Create local branch
command: ostree refs --create local-branch {{ head_csum }}

- name: Update origin file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe drop a comment here explaining why you are modifying the origin file

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment.

Comment thread tests/rpm-ostree/main.yml

- name: Cleanup
command: rpm-ostree cleanup -rpmb

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be rpm_ostree_status_verify here as in previous sections?

Comment thread tests/rpm-ostree/main.yml

- name: Cleanup
command: rpm-ostree cleanup -rpmb

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance to verify that the cleanup was successful with rpm_ostree_status_verify?

Comment thread tests/rpm-ostree/main.yml
command: ostree refs --create local-branch {{ head_csum }}

- name: Update origin file
command: sed -i 's/^\(.*refspec\)=.*$/\1=local-branch/g' {{ current_dir.stdout }}.origin
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add the reload test, or do you mean to add it in a separate PR?

Comment thread tests/rpm-ostree/main.yml Outdated
command: test -n {{ initrd.stdout }}

- name: Get contents of initrd
shell: lsinitrd {{ initrd.stdout }} > lsinitrd.txt
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still change this to use lsinitrd -f to make it an even stronger test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I'm doing something wrong but -f does not seem to do anything.

@mike-nguyen
Copy link
Copy Markdown
Collaborator Author

Much fixups. I believe I have all the requested changes in now this this last fixup!

@jlebon
Copy link
Copy Markdown
Contributor

jlebon commented Jun 7, 2017

Looks good to me! 👍

@miabbott
Copy link
Copy Markdown
Collaborator

miabbott commented Jun 8, 2017

Let's do this! :shipit:

@miabbott miabbott merged commit 470968c into projectatomic:master Jun 8, 2017
@mike-nguyen mike-nguyen deleted the ros branch March 28, 2018 13:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants