Merge lp:~frankban/juju-quickstart/ftest-fixes into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 118
Proposed branch: lp:~frankban/juju-quickstart/ftest-fixes
Merge into: lp:juju-quickstart
Diff against target: 116 lines (+46/-11)
2 files modified
HACKING.rst (+2/-1)
quickstart/tests/functional/test_functional.py (+44/-10)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/ftest-fixes
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+248755@code.launchpad.net

Description of the change

Make ftests fail if Juju env is not ready.

The functional tests are no longer silently skipped
if the default Juju environment cannot be found.

Also fail if the environment is running, as this
would cause it to be destroyed at the end of the
suite.

QA:
- bootstrap your default environment;
- run `make ftest`/`make fcheck` and ensure
  the functional tests fail
  (environment already bootstrapped);
- destroy your environment;
- run `make fcheck` again and ensure all the
  suites complete successfully.

https://codereview.appspot.com/195690043/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :
Download full text (5.7 KiB)

Reviewers: mp+248755_code.launchpad.net,

Message:
Please take a look.

Description:
Make ftests fail if Juju env is not ready.

The functional tests are no longer silently skipped
if the default Juju environment cannot be found.

Also fail if the environment is running, as this
would cause it to be destroyed at the end of the
suite.

QA:
- bootstrap your default environment;
- run `make ftest`/`make fcheck` and ensure
   the functional tests fail
   (environment already bootstrapped);
- destroy your environment;
- run `make fcheck` again and ensure all the
   suites complete successfully.

https://code.launchpad.net/~frankban/juju-quickstart/ftest-fixes/+merge/248755

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/195690043/

Affected files (+48, -11 lines):
   M HACKING.rst
   A [revision details]
   M quickstart/tests/functional/test_functional.py

Index: HACKING.rst
=== modified file 'HACKING.rst'
--- HACKING.rst 2015-01-30 18:06:46 +0000
+++ HACKING.rst 2015-02-05 13:35:53 +0000
@@ -85,6 +85,7 @@
    bootstrapped in the process;
  - a Juju home correctly set up with at least one environment defined in the
    ``environments.yaml`` file;
+- the selected Juju environment not to be in use;
  - SSH keys already generated for the user running the tests;
  - a working Internet connection.

@@ -94,7 +95,7 @@
      make fcheck JUJU_ENV=myenv

  The environment used by the functional suite is destroyed after the tests
-complete. For this reason, **ensure the selected environment is not in
use**.
+complete. The tests fail the selected environment is already in use.

  To run the test using a customized build of Juju, pass the ``JUJU``
environment
  variable to ``make``, e.g.::

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision:
<email address hidden>
+New revision:
<email address hidden>

Index: quickstart/tests/functional/test_functional.py
=== modified file 'quickstart/tests/functional/test_functional.py'
--- quickstart/tests/functional/test_functional.py 2015-02-03 14:13:09 +0000
+++ quickstart/tests/functional/test_functional.py 2015-02-05 12:19:48 +0000
@@ -36,27 +36,55 @@
  FTEST_ENV_VAR = 'JUJU_QUICKSTART_FTESTS'

-def skip_if_disbled(func):
- """Decorate a test method so that it is only run when
required/possible."""
+def skip_or_fail_if_environment_not_ready(func):
+ """Decorate a test method so that it is only run when asked.
+
+ Also fail if the Juju environment is already running, or if the default
+ environment cannot be found.
+ """
      # Check that functional tests are enabled.
      if os.getenv(FTEST_ENV_VAR) != '1':
          return unittest.skip(
              'to run functional tests, set {} to "1"'.format(FTEST_ENV_VAR))
- # Check that a Juju environment can be found.
- env_name = envs.get_default_env_name()
- if env_name is None:
- return unittest.skip('cannot find a configured Juju environment')

      @fun...

Read more...

Revision history for this message
Jeff Pihach (hatch) wrote :

LGTM Thanks for this follow-up!

https://codereview.appspot.com/195690043/

Revision history for this message
Kyle Adams (kadams54) wrote :
Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Make ftests fail if Juju env is not ready.

The functional tests are no longer silently skipped
if the default Juju environment cannot be found.

Also fail if the environment is running, as this
would cause it to be destroyed at the end of the
suite.

QA:
- bootstrap your default environment;
- run `make ftest`/`make fcheck` and ensure
   the functional tests fail
   (environment already bootstrapped);
- destroy your environment;
- run `make fcheck` again and ensure all the
   suites complete successfully.

R=jeff.pihach, kadams54
CC=
https://codereview.appspot.com/195690043

https://codereview.appspot.com/195690043/

Revision history for this message
Francesco Banconi (frankban) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'HACKING.rst'
--- HACKING.rst 2015-01-30 18:06:46 +0000
+++ HACKING.rst 2015-02-05 13:37:25 +0000
@@ -85,6 +85,7 @@
85 bootstrapped in the process;85 bootstrapped in the process;
86- a Juju home correctly set up with at least one environment defined in the86- a Juju home correctly set up with at least one environment defined in the
87 ``environments.yaml`` file;87 ``environments.yaml`` file;
88- the selected Juju environment not to be in use;
88- SSH keys already generated for the user running the tests;89- SSH keys already generated for the user running the tests;
89- a working Internet connection.90- a working Internet connection.
9091
@@ -94,7 +95,7 @@
94 make fcheck JUJU_ENV=myenv95 make fcheck JUJU_ENV=myenv
9596
96The environment used by the functional suite is destroyed after the tests97The environment used by the functional suite is destroyed after the tests
97complete. For this reason, **ensure the selected environment is not in use**.98complete. The tests fail the selected environment is already in use.
9899
99To run the test using a customized build of Juju, pass the ``JUJU`` environment100To run the test using a customized build of Juju, pass the ``JUJU`` environment
100variable to ``make``, e.g.::101variable to ``make``, e.g.::
101102
=== modified file 'quickstart/tests/functional/test_functional.py'
--- quickstart/tests/functional/test_functional.py 2015-02-03 14:13:09 +0000
+++ quickstart/tests/functional/test_functional.py 2015-02-05 13:37:25 +0000
@@ -36,27 +36,55 @@
36FTEST_ENV_VAR = 'JUJU_QUICKSTART_FTESTS'36FTEST_ENV_VAR = 'JUJU_QUICKSTART_FTESTS'
3737
3838
39def skip_if_disbled(func):39def skip_or_fail_if_environment_not_ready(func):
40 """Decorate a test method so that it is only run when required/possible."""40 """Decorate a test method so that it is only run when asked.
41
42 Also fail if the Juju environment is already running, or if the default
43 environment cannot be found.
44 """
41 # Check that functional tests are enabled.45 # Check that functional tests are enabled.
42 if os.getenv(FTEST_ENV_VAR) != '1':46 if os.getenv(FTEST_ENV_VAR) != '1':
43 return unittest.skip(47 return unittest.skip(
44 'to run functional tests, set {} to "1"'.format(FTEST_ENV_VAR))48 'to run functional tests, set {} to "1"'.format(FTEST_ENV_VAR))
45 # Check that a Juju environment can be found.
46 env_name = envs.get_default_env_name()
47 if env_name is None:
48 return unittest.skip('cannot find a configured Juju environment')
4949
50 @functools.wraps(func)50 @functools.wraps(func)
51 def decorated(cls_or_self):51 def decorated(cls_or_self):
52 # Decorate the function to update the received class or instance with52 # If the environment cannot be found, or it is already running,
53 # the Juju env name.53 # do not proceed with setting up the test case class, and make the
54 # tests fail by setting env_error on the class or instance.
55 cls_or_self.env_error = None
56 # Check that a Juju environment can be found.
57 env_name = envs.get_default_env_name()
58 if env_name is None:
59 cls_or_self.env_error = 'cannot find a configured Juju environment'
60 return
61 # Check that the Juju environment is not running.
62 retcode, _, _ = run_juju('status', '-e', env_name)
63 if not retcode:
64 cls_or_self.env_error = (
65 'the {} Juju environment is already running'.format(env_name))
66 return
67 # Update the received class or instance setting the env_name attribute.
54 cls_or_self.env_name = env_name68 cls_or_self.env_name = env_name
55 return func(cls_or_self)69 return func(cls_or_self)
5670
57 return decorated71 return decorated
5872
5973
74def skip_if_environment_not_set(func):
75 """Decorate a test method so that it is not run without an environment.
76
77 The presence of the "env_name" attribute in the TestCase indicates whether
78 or not the tests can be run.
79 """
80 @functools.wraps(func)
81 def decorated(cls_or_self):
82 if hasattr(cls_or_self, 'env_name'):
83 return func(cls_or_self)
84
85 return decorated
86
87
60def run_juju(*args):88def run_juju(*args):
61 """Run the juju command with the given args.89 """Run the juju command with the given args.
6290
@@ -81,7 +109,7 @@
81class TestFunctional(unittest.TestCase):109class TestFunctional(unittest.TestCase):
82110
83 @classmethod111 @classmethod
84 @skip_if_disbled112 @skip_or_fail_if_environment_not_ready
85 def setUpClass(cls):113 def setUpClass(cls):
86 # Run Juju Quickstart to bootstrap Juju and deploy the Juju GUI.114 # Run Juju Quickstart to bootstrap Juju and deploy the Juju GUI.
87 # Note that this is done once per suite. The resulting environment is115 # Note that this is done once per suite. The resulting environment is
@@ -89,11 +117,17 @@
89 cls.retcode, cls.output, cls.error = run_quickstart(cls.env_name)117 cls.retcode, cls.output, cls.error = run_quickstart(cls.env_name)
90118
91 @classmethod119 @classmethod
92 @skip_if_disbled120 @skip_if_environment_not_set
93 def tearDownClass(cls):121 def tearDownClass(cls):
94 # Destroy the environment.122 # Destroy the environment.
95 run_juju('destroy-environment', cls.env_name, '-y', '--force')123 run_juju('destroy-environment', cls.env_name, '-y', '--force')
96124
125 def setUp(self):
126 # Let all the tests fail if an environment error has been detected
127 # in setUpClass.
128 if self.env_error is not None:
129 self.fail(self.env_error)
130
97 def test_executed(self):131 def test_executed(self):
98 # The application successfully completed its execution.132 # The application successfully completed its execution.
99 self.assertEqual(0, self.retcode)133 self.assertEqual(0, self.retcode)

Subscribers

People subscribed via source and target branches