Skip to content

Commit

Permalink
test ports/cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Sep 15, 2022
1 parent 7202475 commit f808831
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
33 changes: 18 additions & 15 deletions src/Containers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,21 +453,23 @@ class Containers extends React.Component {
return null;
}

let cpu = "";
let mem = "";

// As podman does not provide per pod memory/cpu statistics we do the following:
// - don't add up CPU usage, instead display the highest found CPU usage of the containers in a pod
// - add up memory usage so it displays the total memory of the pod.
let cpu = 0;
let mem = 0;
for (const container of pod.Containers) {
const containerStats = containersStats[container.Id + pod.isSystem.toString()];
if (!containerStats) {
if (!containerStats)
continue;
}

if (containerStats.CPU != undefined) {
// TODO: make this consistent..
cpu = containerStats.CPU === 0 ? containerStats.CPU : containerStats.CPU.toFixed(2);
cpu = cpu + "%";
const val = containerStats.CPU === 0 ? containerStats.CPU : containerStats.CPU.toFixed(2);
if (val > cpu)
cpu = val;
}
if (containerStats.MemUsage != undefined && containerStats.MemLimit != undefined)
mem = utils.format_memory_and_limit(containerStats.MemUsage);
if (containerStats.MemUsage != undefined)
mem += containerStats.MemUsage;
}

return {
Expand All @@ -481,7 +483,8 @@ class Containers extends React.Component {
const infraContainer = this.props.containers[pod.InfraId + pod.isSystem.toString()];
const infraContainerDetails = this.props.containersDetails[pod.InfraId + pod.isSystem.toString()];

if (!podStats) {
// Wait till we have valid data before rendering
if (!podStats || podStats.mem <= 0 || podStats.cpu <= 0) {
return null;
}

Expand All @@ -492,14 +495,14 @@ class Containers extends React.Component {
<MicrochipIcon />
</Tooltip>
<Text component={TextVariants.p} className="pf-u-hidden-on-sm">{_("CPU")}</Text>
<Text component={TextVariants.p} className="pod-cpu">{podStats.cpu}</Text>
<Text component={TextVariants.p} className="pod-cpu">{podStats.cpu}%</Text>
</Flex>
<Flex className='pod-stat' spaceItems={{ default: 'spaceItemsSm' }}>
<Tooltip content={_("Memory")}>
<MemoryIcon />
</Tooltip>
<Text component={TextVariants.p} className="pf-u-hidden-on-sm">{_("Memory")}</Text>
<Text component={TextVariants.p} className="pod-memory">{podStats.mem}</Text>
<Text component={TextVariants.p} className="pod-memory">{utils.format_memory_and_limit(podStats.mem)}</Text>
</Flex>
{infraContainer && infraContainerDetails &&
<>
Expand All @@ -509,7 +512,7 @@ class Containers extends React.Component {
enableFlip
bodyContent={renderContainerPublishedPorts(infraContainer.Ports)}
>
<Button isSmall variant="link" className="pod-details-button"
<Button isSmall variant="link" className="pod-details-button pod-details-ports-btn"
icon={<PortIcon className="pod-details-button-color" />}
>
{infraContainer.Ports.length}
Expand All @@ -524,7 +527,7 @@ class Containers extends React.Component {
enableFlip
bodyContent={renderContainerVolumes(infraContainerDetails.Mounts)}
>
<Button isSmall variant="link" className="pod-details-button"
<Button isSmall variant="link" className="pod-details-button pod-details-volumes-btn"
icon={<VolumeIcon className="pod-details-button-color" />}
>
{infraContainerDetails.Mounts.length}
Expand Down
16 changes: 14 additions & 2 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ class TestApplication(testlib.MachineCase):
self.machine.execute("podman exec -i test-pod-1-system sh -c 'dd bs=1024 count=1000000 < /dev/urandom > /dev/null'")
b.wait(lambda: get_pod_cpu_usage("pod-1") > cpu)

# TODO: mounts

self.machine.execute("podman pod stop pod-1")
self.waitPodContainer("pod-1", [{"name": "test-pod-1-system", "image": "alpine", "command": "sleep 100", "state": NOT_RUNNING, "id": containerId}])
self.filter_containers("running")
Expand Down Expand Up @@ -288,6 +286,20 @@ class TestApplication(testlib.MachineCase):
b.click(".pf-c-modal-box button:contains('Delete')")
self.waitPodRow("pod-2", False)

# Volumes / mounts
self.machine.execute("podman pod create -p 9999:9999 -v /tmp:/app --name pod-3")
self.machine.execute("podman pod start pod-3")

self.waitPodContainer("pod-3", [])
# Verify 1 port mapping
b.wait_in_text("#table-pod-3-title .pod-details-ports-btn", "1")
b.click("#table-pod-3-title .pod-details-ports-btn")
b.wait_in_text(".pf-c-popover__content", "0.0.0.0:9999 → 9999/tcp")
# Verify 1 mount
b.wait_in_text("#table-pod-3-title .pod-details-volumes-btn", "1")
b.click("#table-pod-3-title .pod-details-volumes-btn")
b.wait_in_text(".pf-c-popover__content", "/tmp ↔ /app")

@testlib.nondestructive
def testBasicSystem(self):
self._testBasic(True)
Expand Down

0 comments on commit f808831

Please sign in to comment.