def test_update_status_json(self): mock_context = FakeAuroraCommandContext() api = mock_context.get_api('west') api.query_job_updates.return_value = self.get_status_query_response() api.get_job_update_details.return_value = self.get_update_details_response() with contextlib.nested( patch('apache.aurora.client.cli.update.Update.create_context', return_value=mock_context), patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)): cmd = AuroraCommandLine() result = cmd.execute(["beta-update", "status", "--write-json", "west/mcc/test/hello"]) assert result == EXIT_OK mock_context.get_api("west").query_job_updates.assert_called_with(jobKey=AuroraJobKey( 'west', 'mcc', 'test', 'hello')) mock_context.get_api("west").get_job_update_details.assert_called_with('hello') print("============\n%s\n============" % mock_context.get_out_str()) assert mock_context.get_out_str() == textwrap.dedent("""\ { "status": "ROLLING_FORWARD", "last_updated": 14114056030, "started": 1411404927, "update_events": [ { "status": "ROLLING_FORWARD", "timestampMs": 1411404927 }, { "status": "ROLL_FORWARD_PAUSED", "timestampMs": 1411405000 }, { "status": "ROLLING_FORWARD", "timestampMs": 1411405100 } ], "job": "west/mcc/test/hello", "updateId": "fake-update-identifier", "instance_update_events": [ { "action": "INSTANCE_UPDATING", "instance": 1, "timestamp": 1411404930 }, { "action": "INSTANCE_UPDATING", "instance": 2, "timestamp": 1411404940 }, { "action": "INSTANCE_UPDATED", "instance": 1, "timestamp": 1411404950 }, { "action": "INSTANCE_UPDATED", "instance": 2, "timestamp": 1411404960 } ] }""")
def test_list_updates_command(self): mock_context = FakeAuroraCommandContext() mock_context.get_api('west').query_job_updates.return_value = self.get_status_query_response() with contextlib.nested( patch('apache.aurora.client.cli.update.Update.create_context', return_value=mock_context), patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)): cmd = AuroraCommandLine() result = cmd.execute(["beta-update", "list", "west", "--user=me"]) assert result == EXIT_OK assert mock_context.get_out_str() == textwrap.dedent("""\ Job: west/mcc/test/hello, Id: hello, User: me, Status: ROLLING_FORWARD Created: 1411404927, Last Modified 14114056030 Job: west/mch/prod/goodbye, Id: goodbye, User: me, Status: ROLLING_BACK Created: 1411300632, Last Modified 14114092632 Job: west/mcq/devel/gasp, Id: gasp, User: me, Status: ROLL_FORWARD_PAUSED Created: 1411600891, Last Modified 1411800891""")
def test_list_updates_command_json(self): mock_context = FakeAuroraCommandContext() mock_context.get_api('west').query_job_updates.return_value = self.get_status_query_response() with contextlib.nested( patch('apache.aurora.client.cli.update.Update.create_context', return_value=mock_context), patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS)): cmd = AuroraCommandLine() result = cmd.execute(["beta-update", "list", "west", "--user=me", '--write-json']) assert result == EXIT_OK assert mock_context.get_out_str() == textwrap.dedent("""\ [ { "status": "ROLLING_FORWARD", "started": 1411404927, "lastModified": 14114056030, "user": "******", "jobkey": "west/mcc/test/hello", "id": "hello" }, { "status": "ROLLING_BACK", "started": 1411300632, "lastModified": 14114092632, "user": "******", "jobkey": "west/mch/prod/goodbye", "id": "goodbye" }, { "status": "ROLL_FORWARD_PAUSED", "started": 1411600891, "lastModified": 1411800891, "user": "******", "jobkey": "west/mcq/devel/gasp", "id": "gasp" } ]""")