Skip to content

Commit

Permalink
support infra container; new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strzinek authored and jelly committed Aug 18, 2022
1 parent ecfa522 commit b415c15
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/Containers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,6 @@ class Containers extends React.Component {
);
}

// Remove infra containers
filtered = filtered.filter(id => !this.props.containers[id].IsInfra);

filtered.sort((a, b) => {
// Show unhealthy containers first
if (this.props.containersDetails[a] && this.props.containersDetails[b]) {
Expand Down
20 changes: 17 additions & 3 deletions src/PodCreateModal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import {
Button,
Button, Checkbox,
Form, FormGroup, Modal, Radio,
TextInput,
} from '@patternfly/react-core';
Expand All @@ -20,6 +20,7 @@ const systemOwner = "system";
export const PodCreateModal = ({ props, user, close }) => {
const [podName, setPodName] = useState(dockerNames.getRandomName());
const [nameError, setNameError] = useState(null);
const [infra, setInfra] = useState(true);
const [publish, setPublish] = useState([]);
const [volumes, setVolumes] = useState([]);
const [owner, setOwner] = useState(props.systemServiceAvailable ? systemOwner : user);
Expand All @@ -32,6 +33,9 @@ export const PodCreateModal = ({ props, user, close }) => {
if (podName)
createConfig.name = podName;

if (!infra)
createConfig.no_infra = true;

if (publish.length > 0)
createConfig.portmappings = publish
.filter(port => port.containerPort)
Expand Down Expand Up @@ -78,7 +82,9 @@ export const PodCreateModal = ({ props, user, close }) => {
const onValueChanged = (key, value) => {
if (key === "podName") {
setPodName(value);
if (/^[a-zA-Z0-9][a-zA-Z0-9_\\.-]*$/.test(value)) {
if (value === "") {
setNameError(_("Pod name is required."));
} else if (/^[a-zA-Z0-9][a-zA-Z0-9_\\.-]*$/.test(value)) {
setNameError(null);
} else {
setNameError(_("Invalid characters. Name can only contain letters, numbers, and certain punctuation (_ . -)."));
Expand All @@ -104,13 +110,21 @@ export const PodCreateModal = ({ props, user, close }) => {
label={_("System")}
id="create-pod-dialog-owner-system"
isChecked={owner === systemOwner}
isDisabled={!props.systemServiceAvailable}
onChange={() => setOwner(systemOwner)} />
<Radio value={user}
label={cockpit.format("$0 $1", _("User:"), user)}
id="create-pod-dialog-owner-user"
isChecked={owner === user}
isDisabled={!props.systemServiceAvailable}
onChange={() => setOwner(user)} />
</FormGroup>
<FormGroup fieldId="create=pod-dialog-infra">
<Checkbox id="create-pod-dialog-infra"
isChecked={infra}
label={_("Create infra container")}
onChange={value => setInfra(value)} />
</FormGroup>
<DynamicListForm id='create-pod-dialog-publish'
emptyStateString={_("No ports exposed")}
formclass='publish-port-form'
Expand Down Expand Up @@ -140,7 +154,6 @@ export const PodCreateModal = ({ props, user, close }) => {
onEscapePress={() => close() }
title={_("Create pod")}
footer={<>
{dialogError && <ErrorNotification errorMessage={dialogError} errorDetail={dialogErrorDetail} />}
<Button variant='primary' id="create-pod-create-btn" onClick={() => onCreateClicked()}
isDisabled={nameError}>
{_("Create")}
Expand All @@ -150,6 +163,7 @@ export const PodCreateModal = ({ props, user, close }) => {
</Button>
</>}
>
{dialogError && <ErrorNotification errorMessage={dialogError} errorDetail={dialogErrorDetail} />}
{defaultBody}
</Modal>
);
Expand Down
31 changes: 31 additions & 0 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,37 @@ class TestApplication(testlib.MachineCase):
b.click('.pf-c-modal-box__footer #create-image-create-run-btn')
b.wait(lambda: self.getContainerAttr(container_name, "State", sel) in 'Running')

def performContainersKebabAction(self, cmd):
b = self.browser
b.click("#container-over-actions-dropdown")
b.click(f"#containers-containers .pf-c-card__header .pf-c-card__actions .pf-c-toolbar .pf-c-dropdown__menu li:contains({cmd})")

def testCreatePodSystem(self):
self._testCreatePod(True)

def testCreatePodUser(self):
self._testCreatePod(False)

def _testCreatePod(self, auth):
b = self.browser
pod_name = "pod-create"

self.login(auth)

self.performContainersKebabAction("Create pod")

b.wait_visible('#create-pod-dialog-name')

b.set_input_text("#create-pod-dialog-name", pod_name)

# Uncheck infra checkbox - tests are running offline and default infra image may not be available
b.set_checked("#create-pod-dialog-infra", False)

b.click('#create-pod-create-btn')
b.wait_not_present("#create-pod-dialog-name")

self.waitPodRow(pod_name, False)

@testlib.nondestructive
def testRunImageSystem(self):
self._testRunImage(True)
Expand Down

0 comments on commit b415c15

Please sign in to comment.