Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cases for Atomic image. #1

Merged
merged 11 commits into from
Oct 28, 2015
156 changes: 156 additions & 0 deletions atomictests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import unittest
import re
from testutils import system, if_atomic


@unittest.skipUnless(if_atomic(), "It's not an atomic image")
class TestAtomicFirstBootRun(unittest.TestCase):

def test_docker_image_run(self):
out, err, eid = system(
'docker run --rm busybox true && echo "PASS"')
out = out.decode('utf-8')
self.assertEquals('PASS\n', out)


@unittest.skipUnless(if_atomic(), "It's not an Atomic image")
class TestDockerStorageSetup(unittest.TestCase):

def test_journalctl_logs(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to include some "known" good output here so anyone reading can get an idea of what the output should look like. This is good for when tests fail and someone tries to go in to see what the test was doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, will do it in the futuire

"""Test journalctl logs for docker-storage-setup"""
out, err, eid = system(
'journalctl -o cat --unit docker-storage-setup.service'
)
out = out.decode('utf-8')
self.assertTrue(re.search(r'CHANGED: partition=\d', out))
self.assertTrue(
re.search(r'Physical volume "/dev/vd[a-z]\d" changed', out))
self.assertTrue('1 physical volume(s) resized' in out)
self.assertTrue(
'Size of logical volume atomicos/root changed from' in out)
self.assertTrue(
'Logical volume root successfully resized' in out)
self.assertTrue('Rounding up size to full physical extent' in out)
self.assertTrue('Logical volume "docker-meta" created' in out)
self.assertTrue('Logical volume "docker-data" created' in out)

def test_lsblk_output(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment from above

"""Test output for lsblk"""
out, err, eid = system('sudo lsblk')
out = out.decode('utf-8')
self.assertTrue(
re.search(r'atomicos-root.*\d+(?:.\d+)?G.*lvm.*/sysroot.*\n', out)
)
self.assertTrue(
re.search(r'atomicos-docker--meta.*\d+(?:.\d+)?M.*lvm', out)
)
self.assertTrue(
re.search(r'atomicos-docker--data.*\d+(?:.\d+)?G.*lvm', out)
)


@unittest.skipUnless(if_atomic(), "It's not an Atomic image")
class TestDockerInstalled(unittest.TestCase):

def test_run(self):
out, err, eid = system('rpm -q docker')
out = out.decode('utf-8')
self.assertTrue('docker' in out)


@unittest.skipUnless(if_atomic(), "It's not an Atomic image")
class TestAtomicUpgradeRun(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Add docs that explains the goal of writing file1 and that we will use it later.. etc..


def test_upgrade_run(self):
out, err, eid = system('sudo rpm-ostree status')
out = out.decode('utf-8')
self.assertTrue(out)
out, err, eid = system('sudo ostree admin status')
out = out.decode('utf-8')
self.assertTrue(out)

# We create a file /etc/file1 before running rpm-ostree upgrade.
# This file should persist, even in rolling back the upgrade.
# This we assert in
# TestAtomicRollbackPostReboot.test_atomic_rollback_post_reboot
out, err, eid = system(
'sudo cat /ostree/repo/refs/heads/ostree/0/1/0 > /etc/file1')
err = err.decode('utf-8')
self.assertFalse(err)
out, err, eid = system('sudo rpm-ostree upgrade')
err = err.decode('utf-8')
# Assert successful run
self.assertFalse(err)


@unittest.skipUnless(if_atomic(), "It's not an Atomic image")
class TestAtomicUpgradePostReboot(unittest.TestCase):

def test_upgrade_post_reboot(self):
out, err, eid = system(
'docker run --rm busybox true && echo "PASS"')
out = out.decode('utf-8')
self.assertEquals('PASS\n', out)


@unittest.skipUnless(if_atomic(), "It's not an Atomic image")
class TestAtomicRollbackRun(unittest.TestCase):

def test_atomic_rollback_run(self):
# We make changes to the system by creating /etc/file2 before
# running rollback. Once rollback is run, /etc/file2 will be
# removed. We assert that in the following test case.
out, err, eid = system(
'sudo cat /ostree/repo/refs/heads/ostree/1/1/0 > /etc/file2')
err = err.decode('utf-8')
self.assertFalse(err)

out, err, eid = system('sudo rpm-ostree rollback')
err = err.decode('utf-8')
self.assertFalse(err)


@unittest.skipUnless(if_atomic(), "It's not an Atomic image")
class TestAtomicRollbackPostReboot(unittest.TestCase):

def test_atomic_rollback_post_reboot(self):
out, err, eid = system('rpm-ostree status')
out = out.decode('utf-8')
self.assertTrue(out)

# Assert that file1 is present
out, err, eid = system('sudo cat /etc/file1')
out = out.decode('utf-8')
self.assertTrue(out)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you assertTrue(out) on line 108 you assertTrue(err). Which is it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I get it now.. The one on line 108 is supposed to fail because we did a rollback.. Yeah we need to add comments in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added comments now


# Assert that file2 is not present
out, err, eid = system('sudo cat /etc/file2')
err = err.decode('utf-8')
self.assertTrue(err)

# Assert that running busybox docker image works after rollback
out, err, eid = system(
'docker run --rm busybox true && echo "PASS"')
out = out.decode('utf-8')
self.assertEqual(out, 'PASS\n')


@unittest.skipUnless(if_atomic(), "It's not an Atomic image")
class TestAtomicDockerImage(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just call this TestDockerImage


def test_docker_image(self):
out, err, eid = system(
'curl -O https://dl.fedoraproject.org/pub/alt/stage/23_TC1/Docker'
Copy link
Contributor

Choose a reason for hiding this comment

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

Any place we can put this URL so that we can easily change it in the future? Some constants file maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

laters ;)

'/x86_64/Fedora-Docker-Base-23_TC1-20150929.x86_64.tar.xz')
out, err, eid = system(
'sudo docker load -i '
'Fedora-Docker-Base-23_TC1-20150929.x86_64.tar.xz')
out, err, eid = system(
'sudo docker run -it --rm '
'Fedora-Docker-Base-23_TC1-20150929.x86_64 '
'true && echo "PASS" || echo "FAIL"')
out = out.decode('utf-8')
self.assertEqual(out, 'PASS\n')

if __name__ == '__main__':
unittest.main()
14 changes: 14 additions & 0 deletions fedora.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@ sudo python3 -m unittest tunirtests.cloudservice.TestServiceManipulation -v
@@ sudo reboot
SLEEP 30
sudo python3 -m unittest tunirtests.cloudservice.TestServiceAfter -v

sudo python3 -m unittest tunirtests.atomictests.TestDockerInstalled -v
sudo python3 -m unittest tunirtests.atomictests.TestDockerStorageSetup -v
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add TestAtomicFirstBootRun() where we run docker run --rm busybox true && echo "PASS" on first boot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

sudo python3 -m unittest tunirtests.atomictests.TestAtomicUpgradeRun -v

@@ sudo reboot
SLEEP 30
sudo python3 -m unittest tunirtests.atomictests.TestAtomicUpgradePostReboot
sudp python3 -m unittest tunirtests.atomictests.TestAtomicRollbackRun

@@ sudo reboot
SLEEP 30
sudo python3 -m unittest tunirtests.atomictests.TestAtomicRollbackPostReboot
sudo python3 -m unittest tunirtests.atomictests.TestAtomicDockerImage