Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions tests/integration-tests/tests/cli_commands/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# or in the "LICENSE.txt" file accompanying this file.
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import datetime
import json
import logging
import os as os_lib
Expand All @@ -21,7 +20,6 @@
import botocore
import pytest
from assertpy import assert_that
from dateutil.parser import parse as date_parse
from framework.credential_providers import run_pcluster_command
from remote_command_executor import RemoteCommandExecutor
from utils import (
Expand Down Expand Up @@ -405,37 +403,18 @@ def _test_pcluster_get_cluster_log_events(cluster):
cluster_info = cluster.describe_cluster()
cfn_init_log_stream = instance_stream_name(cluster_info["headNode"], "cfn-init")

# Get the first event to establish time boundary for testing
initial_events = cluster.get_log_events(cfn_init_log_stream, limit=1, start_from_head=True)
first_event = initial_events["events"][0]
first_event_time_str = first_event["timestamp"]
first_event_time = date_parse(first_event_time_str)
before_first = (first_event_time - datetime.timedelta(seconds=1)).isoformat()
after_first = (first_event_time + datetime.timedelta(seconds=1)).isoformat()

# args, expect_first, expect_count
test_cases = [
({}, None, None),
({"limit": 1}, False, 1),
({"limit": 2, "start_from_head": True}, True, 2),
({"limit": 1, "start_time": before_first, "end_time": after_first, "start_from_head": True}, True, 1),
({"limit": 1, "end_time": before_first}, None, 0),
({"limit": 1, "start_time": after_first, "start_from_head": True}, False, 1),
({"limit": 1, "next_token": initial_events["nextToken"]}, False, 1),
({"limit": 1, "next_token": initial_events["nextToken"], "start_from_head": True}, False, 1),
]

for args, expect_first, expect_count in test_cases:
events = cluster.get_log_events(cfn_init_log_stream, **args)["events"]

if expect_count is not None:
assert_that(events).is_length(expect_count)

if expect_first is True:
assert_that(events[0]["message"]).is_equal_to(first_event["message"])

if expect_first is False:
assert_that(events[0]["message"]).is_not_equal_to(first_event["message"])
# GetLogEvents can return empty pages while more events are available,
# so page forward until the token stops changing, which marks the end of the stream.
events = []
next_token = None
while True:
response = cluster.get_log_events(cfn_init_log_stream, start_from_head=True, next_token=next_token)
events.extend(response["events"])
if not response.get("nextToken") or response["nextToken"] == next_token:
break
next_token = response["nextToken"]

assert_that(events).is_not_empty()


def _test_pcluster_get_cluster_stack_events(cluster):
Expand Down
45 changes: 12 additions & 33 deletions tests/integration-tests/tests/createami/test_createami.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# or in the "LICENSE.txt" file accompanying this file.
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import datetime
import json
import logging
import re
Expand All @@ -22,7 +21,6 @@
from assertpy import assert_that, soft_assertions
from botocore.exceptions import ClientError
from cfn_stacks_factory import CfnStack
from dateutil.parser import parse as date_parse
from remote_command_executor import RemoteCommandExecutor
from retrying import retry
from time_utils import minutes, seconds
Expand Down Expand Up @@ -359,37 +357,18 @@ def _test_get_image_log_events(image):
logging.info("Testing that pcluster get-image-log-events is working as expected")
log_stream_name = image.build_log_stream_name

# Get the first event to establish time boundary for testing
initial_events = image.get_log_events(log_stream_name, limit=1, start_from_head=True)
first_event = initial_events["events"][0]
first_event_time_str = first_event["timestamp"]
first_event_time = date_parse(first_event_time_str)
before_first = (first_event_time - datetime.timedelta(seconds=1)).isoformat()
after_first = (first_event_time + datetime.timedelta(seconds=1)).isoformat()

# args, expect_first, expect_count
test_cases = [
({}, None, None),
({"limit": 1}, False, 1),
({"limit": 2, "start_from_head": True}, True, 2),
({"limit": 1, "start_time": before_first, "end_time": after_first, "start_from_head": True}, True, 1),
({"limit": 1, "end_time": before_first}, None, 0),
({"limit": 1, "start_time": after_first, "start_from_head": True}, False, 1),
({"limit": 1, "next_token": initial_events["nextToken"]}, False, 1),
({"limit": 1, "next_token": initial_events["nextToken"], "start_from_head": True}, False, 1),
]

for args, expect_first, expect_count in test_cases:
events = image.get_log_events(log_stream_name, **args)["events"]

if expect_count is not None:
assert_that(events).is_length(expect_count)

if expect_first is True:
assert_that(events[0]["message"]).contains(first_event["message"])

if expect_first is False:
assert_that(events[0]["message"]).does_not_contain(first_event["message"])
# GetLogEvents can return empty pages while more events are available,
# so page forward until the token stops changing, which marks the end of the stream.
events = []
next_token = None
while True:
response = image.get_log_events(log_stream_name, start_from_head=True, next_token=next_token)
events.extend(response["events"])
if not response.get("nextToken") or response["nextToken"] == next_token:
break
next_token = response["nextToken"]

assert_that(events).is_not_empty()


def _set_s3_bucket_policy(bucket_name, partition, region):
Expand Down
Loading