Merge lp:~canonical-platform-qa/snappy-ecosystem-tests/fix_private_snap_test into lp:snappy-ecosystem-tests

Proposed by Omer Akram
Status: Merged
Approved by: Heber Parrucci
Approved revision: 96
Merged at revision: 48
Proposed branch: lp:~canonical-platform-qa/snappy-ecosystem-tests/fix_private_snap_test
Merge into: lp:snappy-ecosystem-tests
Diff against target: 74 lines (+42/-1)
2 files modified
snappy_ecosystem_tests/helpers/snapd/snapd.py (+37/-0)
snappy_ecosystem_tests/tests/test_install_private_snap.py (+5/-1)
To merge this branch: bzr merge lp:~canonical-platform-qa/snappy-ecosystem-tests/fix_private_snap_test
Reviewer Review Type Date Requested Status
Heber Parrucci (community) Approve
platform-qa-bot continuous-integration Approve
Review via email: mp+320255@code.launchpad.net

Commit message

Stabilize private snap install test.

Description of the change

Stabilize private snap install test. The test was failing sometimes as there is a timing issue between the time a snap is published and it actually being installable. The difference is closely 1-2 seconds. To ensure stability we first check if the snap is really available by calling 'snap info'.

To post a comment you must log in.
Revision history for this message
Omer Akram (om26er) wrote :

Test results: http://paste.ubuntu.com/24197140/ -- Excuse the failing tests, that's because I am running these tests in a remote environment where X is not available.

Revision history for this message
Omer Akram (om26er) wrote :

*test.

On Sat, Mar 18, 2017 at 1:07 AM, Omer Akram <email address hidden>
wrote:

> Test results: http://paste.ubuntu.com/24197140/ -- Excuse the failing
> tests, that's because I am running these tests in a remote environment
> where X is not available.
> --
> https://code.launchpad.net/~canonical-platform-qa/snappy-
> ecosystem-tests/fix_private_snap_test/+merge/320255
> Your team Canonical Platform QA Team is subscribed to branch
> lp:~canonical-platform-qa/snappy-ecosystem-tests/fix_private_snap_test.
>

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
94. By Omer Akram

Be absolute when waiting for snap to publish

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
95. By Omer Akram

more reusable code

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
96. By Omer Akram

More rock solid is_published

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Heber Parrucci (heber013) wrote :

Code LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy_ecosystem_tests/helpers/snapd/snapd.py'
2--- snappy_ecosystem_tests/helpers/snapd/snapd.py 2017-03-16 16:49:31 +0000
3+++ snappy_ecosystem_tests/helpers/snapd/snapd.py 2017-03-19 15:27:27 +0000
4@@ -22,6 +22,7 @@
5
6 import json
7 import logging
8+from time import sleep
9
10 import yaml
11
12@@ -166,3 +167,39 @@
13 return Snapd._parse_output(
14 self.run_snapd_command_ssh(COMMAND_FIND.format(
15 search_term=keyword)))
16+
17+ def is_published(self, snap_name, revision, channel='stable'):
18+ """Return bool representing whether a snap is published.
19+
20+ :param snap_name: Name of the snap to check.
21+ :param revision: Revision to check.
22+ :param channel: Channel to check.
23+ :return: True if published, False otherwise.
24+ """
25+ try:
26+ return int(self.info(snap_name)['channels'][channel].split()[1]
27+ .strip('()')) >= int(revision)
28+ except (ValueError, KeyError):
29+ return False
30+
31+ def wait_for_publish(self, snap_name, revision, channel='stable',
32+ retry_attempts=10, retry_interval=1):
33+ """Waits for the requested snap to publish by checking if its info
34+ can be retrieved.
35+
36+ :param snap_name: Name of the snap to wait for publish.
37+ :param revision: Snap revision number to check.
38+ :param channel: Channel to check snap in.
39+ :param retry_attempts: Number of times to check for the publish.
40+ :param retry_interval: Time between each attempt.
41+ :raises ValueError: If the snap is not found published after the
42+ given time.
43+ """
44+ for _ in range(retry_attempts):
45+ if self.is_published(snap_name, revision, channel):
46+ break
47+ else:
48+ sleep(retry_interval)
49+ else:
50+ raise ValueError('Snap not published, waited {} seconds.'.format(
51+ retry_attempts * retry_interval))
52
53=== modified file 'snappy_ecosystem_tests/tests/test_install_private_snap.py'
54--- snappy_ecosystem_tests/tests/test_install_private_snap.py 2017-03-16 19:28:12 +0000
55+++ snappy_ecosystem_tests/tests/test_install_private_snap.py 2017-03-19 15:27:27 +0000
56@@ -49,13 +49,17 @@
57 """Test to register and upload a private snap via the REST API
58 and installing through snapd."""
59 snap_name = get_random_snap_name()
60+ channels = ['stable']
61+ revision = '1'
62 self.assertTrue(self.store.register(snap_name, private=True),
63 'Unable to register snap')
64 # Upload the snap and wait for its processing on server to finish.
65 tracker = self.store.upload(
66 snap_name, self.snap_builder.build_and_pull(snap_name, '0.1'))
67 tracker.track()
68- self.store.release(snap_name, '1', ['stable'])
69+ response = self.store.release(snap_name, revision, channels)
70+ self.assertEqual(channels, response.get('opened_channels', None))
71+ self.snapd.wait_for_publish(snap_name, revision, channels[0])
72 self.snapd.install(snap_name)
73 self.addCleanup(self.snapd.remove, snap_name)
74 self.assertTrue(self.snapd.is_installed, snap_name)

Subscribers

People subscribed via source and target branches