~pjdc/mojo/clarify-container-class-message

« back to all changes in this revision

Viewing changes to mojo/tests/test_juju2.py

  • Committer: mergebot at canonical
  • Author(s): "Tom Haddon"
  • Date: 2020-07-06 07:04:06 UTC
  • mfrom: (557.2.2 wait-k8s)
  • Revision ID: mergebot@juju-139df4-prod-is-toolbox-0.canonical.com-20200706070406-gxg564p401dw8n3r
Add wait-for-workload as an option to juju-check-wait phase, defaulting to False



Reviewed-on: https://code.launchpad.net/~mthaddon/mojo/juju-check-wait-for-workload/+merge/386819
Reviewed-by: Stuart Bishop <stuart.bishop@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        # Now call with wait_for_steady=True and confirm wait is called even
128
128
        # though juju status is okay.
129
129
        self.status.check_and_wait(wait_for_steady=True, max_wait=300)
130
 
        _wait.assert_called_with(max_wait=300)
131
 
        # Also confirm our logging is as expected.
132
 
        expected_logging_args_list = [
133
 
            "Waiting up to 1800 seconds for environment to become ready (not blocked or in maintenance)",
134
 
            "Environment is ready (not blocked or in maintenance)",
135
 
            "Waiting up to 300 seconds for environment to reach steady state (not running any hook)",
 
130
        _wait.assert_called_with(max_wait=300, wait_for_workload=False)
 
131
        # Also confirm our logging is as expected.
 
132
        expected_logging_args_list = [
 
133
            "Waiting up to 1800 seconds for environment to become ready (not blocked or in maintenance)",
 
134
            "Environment is ready (not blocked or in maintenance)",
 
135
            "Waiting up to 300 seconds for environment to reach steady state (not running any hook), "
 
136
            "with wait-for-workload set to False",
 
137
            "Environment has reached steady state (not running any hook)",
 
138
        ]
 
139
        self.assertEquals(len(_logging_info.call_args_list), len(expected_logging_args_list))
 
140
        for i, call in enumerate(_logging_info.call_args_list):
 
141
            self.assertEquals(call, mock.call(expected_logging_args_list[i]))
 
142
        _logging_info.reset_mock()
 
143
 
 
144
        # Now call with wait_for_workload=True as well and confirm that's
 
145
        # passed to juju-check-wait and logged correctly.
 
146
        self.status.check_and_wait(wait_for_steady=True, max_wait=300, wait_for_workload=True)
 
147
        _wait.assert_called_with(max_wait=300, wait_for_workload=True)
 
148
        # Also confirm our logging is as expected.
 
149
        expected_logging_args_list = [
 
150
            "Waiting up to 1800 seconds for environment to become ready (not blocked or in maintenance)",
 
151
            "Environment is ready (not blocked or in maintenance)",
 
152
            "Waiting up to 300 seconds for environment to reach steady state (not running any hook), "
 
153
            "with wait-for-workload set to True",
136
154
            "Environment has reached steady state (not running any hook)",
137
155
        ]
138
156
        self.assertEquals(len(_logging_info.call_args_list), len(expected_logging_args_list))
185
203
        with mock.patch("mojo.juju.status.major_version", new=2):
186
204
            self.status = mojo.juju.status.Juju2Status()
187
205
        status_mock.return_value = self._testdata_from_file("juju2-busy.yaml")
188
 
        with mock.patch("mojo.juju.status.wait", new=lambda max_wait: None):
 
206
        with mock.patch("mojo.juju.status.wait"):
189
207
            self.status.check_and_wait(wait_for_steady=True, timeout=1)
190
208
 
191
209
    @mock.patch("subprocess.check_output")