Skip to content
Snippets Groups Projects
Commit 7a82eaf1 authored by Takumaru Sekine's avatar Takumaru Sekine Committed by Yas Naoi
Browse files

Issue #3298293 by sekinet, kumikoono, yas: Add a BDD test suite for K8s Pod Schedules

parent ba66b0fc
No related branches found
No related tags found
3 merge requests!1316Issue #3310263: Release 4.5.0,!1260Issue #3307397: Release 4.4.0,!1188Issue #3298293: Add a BDD test suite for K8s Pod Schedules
......@@ -23,6 +23,8 @@ Feature: Create a Drupal role for K8s and a user as "Administrator"
And I check the box "Access {{ cloud_service_provider_name }}"
# Allow to launch an instance.
And I check the box "Launch approved cloud launch template"
# Temporarily adds any permissions.
And I check the box "View any K8s pod"
And I press "Save permissions"
And I should see the success message "The changes have been saved."
And I should see neither error nor warning messages
......
@minimal @ci_job
Feature: Create and delete a pod for K8s as "Authenticated User"
@api @javascript
Scenario: Create a Pod Schedules
Given I am logged in as user "{{ user_name }}"
When I visit "/clouds/k8s/{{ cloud_context }}/pod/add"
And I should see the heading "Add Pod"
And I select "{{ namespace }}" from "Namespace"
And I fill in "Detail" with:
"""
apiVersion: v1
kind: Pod
metadata:
name: {{ pod_name }}
spec:
containers:
- name: {{ container_name }}
image: {{ image_version }}
ports:
- containerPort: {{ port }}
"""
And I check the box "Enable time scheduler"
And I select "{{ start_elapsed_minute }}" minutes later now from the start-up time
And I select "{{ stop_elapsed_minute }}" minutes later now from the stop time
When I press "Save"
And I wait for AJAX to finish
And the url should match "/clouds/k8s/{{ cloud_context }}/pod"
And I should see the success message "has been created"
And I should see neither error nor warning messages
# Visit schedule edit view to see start-up time.
When I visit "/clouds/k8s/{{ cloud_context }}/schedule"
Then I should see the link "{{ namespace }}_{{ pod_name }}"
And I click "{{ namespace }}_{{ pod_name }}"
And I click "Edit"
When I wait until start-up time for schedule
And I visit "/clouds/k8s/{{ cloud_context }}/pod"
Given I run drush cron
Then I click "Refresh"
And I should see "{{ pod_name }}" in the "{{ namespace }}" row
# Visit schedule edit view to see stop time.
When I visit "/clouds/k8s/{{ cloud_context }}/schedule"
Then I should see the link "{{ namespace }}_{{ pod_name }}"
And I click "{{ namespace }}_{{ pod_name }}"
And I click "Edit"
When I wait until stop time for schedule
And I visit "/clouds/k8s/{{ cloud_context }}/pod"
Given I run drush cron
Then I click "Refresh"
And I should not see the link "{{ pod_name }}"
@api @javascript
Scenario: Read the Pod Schedules
Given I am logged in as user "{{ user_name }}"
When I visit "/clouds/k8s/{{ cloud_context }}/schedule"
And I should see "{{ namespace }}_{{ pod_name }}" in the "{{ namespace }}" row
And I click "{{ namespace }}_{{ pod_name }}"
And the url should match "clouds/k8s/{{ cloud_context }}/schedule/"
And I should see "{{ pod_name }}"
And I should see "{{ namespace }}"
And I should see neither error nor warning messages
@api @javascript
Scenario: Update the Pod Schedules
Given I am logged in as user "{{ user_name }}"
When I visit "/clouds/k8s/{{ cloud_context }}/schedule"
And I should see the link "{{ namespace }}_{{ pod_name }}"
And I click "{{ namespace }}_{{ pod_name }}"
Then the url should match "/clouds/k8s/{{ cloud_context }}/schedule/"
And I click "Edit"
And I select "{{ start_elapsed_minute }}" minutes later now from the start-up time
And I select "{{ stop_elapsed_minute }}" minutes later now from the stop time
And I press "Save"
And I wait for AJAX to finish
Then the url should match "/clouds/k8s/{{ cloud_context }}/schedule"
And I should see the success message "has been updated"
And I should see neither error nor warning messages
And I click "{{ namespace }}_{{ pod_name }}"
Then the url should match "/clouds/k8s/{{ cloud_context }}/schedule/"
# Visit schedule edit view to see start-up time.
And I click "Edit"
When I wait until start-up time for schedule
And I visit "/clouds/k8s/{{ cloud_context }}/pod"
Given I run drush cron
Then I click "Refresh"
And I should see "{{ pod_name }}" in the "{{ namespace }}" row
# Visit schedule edit view to see stop time.
When I visit "/clouds/k8s/{{ cloud_context }}/schedule"
Then I should see the link "{{ namespace }}_{{ pod_name }}"
And I click "{{ namespace }}_{{ pod_name }}"
And I click "Edit"
When I wait until stop time for schedule
And I visit "/clouds/k8s/{{ cloud_context }}/pod"
Given I run drush cron
Then I click "Refresh"
And I should not see the link "{{ pod_name }}"
@api @javascript
Scenario: Delete the Pod Schedules
Given I am logged in as user "{{ user_name }}"
When I visit "/clouds/k8s/{{ cloud_context }}/schedule"
And I should see the link "{{ namespace }}_{{ pod_name }}"
And I click "{{ namespace }}_{{ pod_name }}"
And the url should match "/k8s/{{ cloud_context }}/schedule/"
And I click "Delete" in the "actions"
And the url should match "/delete"
And I press "Delete"
And I wait for AJAX to finish
Then I should be on "/clouds/k8s/{{ cloud_context }}/schedule"
And I should see the success message "has been deleted"
And I should see neither error nor warning messages
......@@ -255,3 +255,7 @@ namespace_annotations_item_value_field:
edit-annotations-1-item-value
api_service_name:
v1alpha1.default.example.com
start_elapsed_minute:
3
stop_elapsed_minute:
6
......@@ -19,4 +19,111 @@ class FeatureContext extends RawDrupalContext {
public function __construct() {
}
/**
* Fill in the hour/minute based on the elapsed minute from the current time.
*
* @var hour_id
* The ID of the hour list.
* @var minute_id
* The ID of the minute list.
* @var elapsed_minute
* The elapsed minute.
*/
private function selectTimeByElapsedTime(string $hour_id, string $minute_id, string $elapsed_minute) {
$element = $this->getSession()->getPage();
$hour_select = $element->findById($hour_id);
$minute_select = $element->findById($minute_id);
if (empty($hour_select)) {
throw new \Exception(sprintf('The select with "%s" was not found on the page %s', $hour_id, $this->getSession()->getCurrentUrl()));
}
if (empty($minute_select)) {
throw new \Exception(sprintf('The select with "%s" was not found on the page %s', $minute_id, $this->getSession()->getCurrentUrl()));
}
$time = new \DateTime('now', new \DateTimeZone(date_default_timezone_get()));
$time->add(\DateInterval::createFromDateString("$elapsed_minute minute"));
$hour = $time->format('H');
$minute = $time->format('i');
$hour_select->selectOption($hour, FALSE);
$minute_select->selectOption($minute, FALSE);
}
/**
* Wait until the specified schedule time.
*
* @var hour_id
* The ID of the hour list.
* @var minute_id
* The ID of the minute list.
*/
private function waitUntilScheduleTime(string $hour_id, string $minute_id): void {
$resource_startup_wait_minute = 1;
$element = $this->getSession()->getPage();
$hour_select = $element->findById($hour_id);
$minute_select = $element->findById($minute_id);
if (empty($hour_select)) {
throw new \Exception(sprintf('The select with "%s" was not found on the page %s', $hour_id, $this->getSession()->getCurrentUrl()));
}
if (empty($minute_select)) {
throw new \Exception(sprintf('The select with "%s" was not found on the page %s', $minute_id, $this->getSession()->getCurrentUrl()));
}
$hour = $hour_select->getValue();
$minute = $minute_select->getValue();
$now_time = new \DateTime('now', new \DateTimeZone(date_default_timezone_get()));
$wait_until_time = new \DateTime('', new \DateTimeZone(date_default_timezone_get()));
if (empty($hour)) {
throw new \Exception(sprintf('Failed to get the value of %s select.', $hour_select));
}
if (empty($minute)) {
throw new \Exception(sprintf('Failed to get the value of %s select.', $minute_select));
}
$wait_until_time->setTime($hour, $minute);
$wait_until_time->add(\DateInterval::createFromDateString("$resource_startup_wait_minute Minutes"));
$wait_time = $wait_until_time->diff($now_time);
// Converts hours, minutes, and seconds to seconds.
$wait_second = $wait_time->h * 60 * 60 + $wait_time->i * 60 + $wait_time->s;
sleep($wait_second);
}
/**
* Select the start time in elapsed minute from the current time.
*
* @When I select :elapsed_minutes minutes later now from the start-up time
*/
public function selectScheduleStartupTimeByElapsedTime($elapsed_minutes) {
$this->selectTimeByElapsedTime('edit-start-hour', 'edit-start-minute', $elapsed_minutes);
}
/**
* Select the stop time in elapsed minute from the current time.
*
* @When I select :elapsed_minutes minutes later now from the stop time
*/
public function selectScheduleStopTimeByElapsedTime($elapsed_minutes) {
$this->selectTimeByElapsedTime('edit-stop-hour', 'edit-stop-minute', $elapsed_minutes);
}
/**
* Wait until the stop time for Schedule.
*
* @When I wait until start-up time for schedule
*/
public function waitUntilStartupTimeForSchedule(): void {
$this->waitUntilScheduleTime('edit-start-hour', 'edit-start-minute');
}
/**
* Wait until the stop time for Schedule.
*
* @When I wait until stop time for schedule
*/
public function waitUntilStopTimeForSchedule(): void {
$this->waitUntilScheduleTime('edit-stop-hour', 'edit-stop-minute');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment