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
16 changes: 0 additions & 16 deletions src/app/base/components/StatusBar/StatusBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ afterEach(() => {
Object.assign(import.meta.env, { ...originalEnv });
});

it("can show if the MAAS is a snap installation", () => {
state.general.installType.data = "snap";

renderWithProviders(<StatusBar />, { state });

expect(screen.getByText(/(snap)/i)).toBeInTheDocument();
});

it("can show if the MAAS is a deb installation", () => {
state.general.installType.data = "deb";

renderWithProviders(<StatusBar />, { state });

expect(screen.getByText(/(deb)/i)).toBeInTheDocument();
});

it("can show if a machine is currently commissioning", () => {
state.machine.items = [
factory.machineDetails({
Expand Down
13 changes: 3 additions & 10 deletions src/app/base/components/StatusBar/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ import {
isRack,
isRegionAndRack,
} from "@/app/store/controller/utils";
import { generalActions } from "@/app/store/general";
import {
installType as installTypeSelectors,
version as versionSelectors,
} from "@/app/store/general/selectors";
import { version as versionSelectors } from "@/app/store/general/selectors";
import machineSelectors from "@/app/store/machine/selectors";
import type { MachineDetails } from "@/app/store/machine/types";
import {
Expand Down Expand Up @@ -120,7 +116,6 @@ export const StatusBar = (): React.ReactElement | null => {
const maasName = useSelector(configSelectors.maasName);
const allowUsabilla = useUsabilla();
const msmRunning = useSelector(msmSelectors.running);
const installType = useSelector(installTypeSelectors.get);
const { toggleListView, notifications, countBySeverity, isListView } =
useToastNotification();

Expand All @@ -146,7 +141,7 @@ export const StatusBar = (): React.ReactElement | null => {

const hasNotifications = notifications.length > 0;

useFetchActions([msmActions.fetch, generalActions.fetchInstallType]);
useFetchActions([msmActions.fetch]);

if (!(maasName && version)) {
return null;
Expand Down Expand Up @@ -189,9 +184,7 @@ export const StatusBar = (): React.ReactElement | null => {
<div className="p-status-bar__primary u-flex--no-shrink u-flex--wrap">
<strong data-testid="status-bar-maas-name">{maasName} MAAS</strong>
:&nbsp;
<span data-testid="status-bar-version">
{version} ({installType})
</span>
<span data-testid="status-bar-version">{version}</span>
</div>
<div className="p-status-bar__primary u-flex--no-shrink u-flex--wrap">
<span data-testid="status-bar-msm-status">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import ControllerStatusCard, { Labels } from "./ControllerStatusCard";

import { controllerActions } from "@/app/store/controller";
import {
ControllerInstallType,
ImageSyncStatus,
} from "@/app/store/controller/types";
import { ImageSyncStatus } from "@/app/store/controller/types";
import { NodeType } from "@/app/store/types/node";
import * as factory from "@/testing/factories";
import {
Expand Down Expand Up @@ -92,43 +89,10 @@ it("dispatches an action to stop polling images on unmount", () => {
);
});

it("renders correct version info for a deb install", async () => {
const controller = factory.controllerDetails({
versions: factory.controllerVersions({
current: factory.controllerVersionInfo({ version: "1.2.3" }),
install_type: ControllerInstallType.DEB,
origin: "ppa:some/ppa",
}),
});
const state = factory.rootState({
controller: factory.controllerState({ items: [controller] }),
});

renderWithProviders(<ControllerStatusCard controller={controller} />, {
state,
});

await userEvent.hover(
screen.getByRole("button", { name: Labels.VersionDetails })
);
await waitFor(() => {
expect(screen.getByLabelText(Labels.Version).textContent).toBe(
"Version: 1.2.3"
);
});

await waitFor(() => {
expect(screen.getByLabelText(Labels.Origin).textContent).toBe(
"Deb: ppa:some/ppa"
);
});
});

it("renders correct version info for a snap install", async () => {
const controller = factory.controllerDetails({
versions: factory.controllerVersions({
current: factory.controllerVersionInfo({ version: "1.2.3" }),
install_type: ControllerInstallType.SNAP,
origin: "1.2/edge",
}),
});
Expand Down Expand Up @@ -157,11 +121,10 @@ it("renders correct version info for a snap install", async () => {
});
});

it("renders correct version info for an unknown install type", async () => {
it("renders fallback version info when the version is unknown", async () => {
const controller = factory.controllerDetails({
versions: factory.controllerVersions({
current: factory.controllerVersionInfo({ version: "" }),
install_type: ControllerInstallType.UNKNOWN,
origin: "nowhere",
}),
});
Expand All @@ -185,7 +148,7 @@ it("renders correct version info for an unknown install type", async () => {
await waitFor(() => {
expect(
within(screen.getByRole("tooltip")).getByLabelText(Labels.Origin)
).toHaveTextContent("Origin: nowhere");
).toHaveTextContent("Channel: nowhere");
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { useDispatch, useSelector } from "react-redux";
import TooltipButton from "@/app/base/components/TooltipButton";
import { controllerActions } from "@/app/store/controller";
import controllerSelectors from "@/app/store/controller/selectors";
import {
ControllerInstallType,
ImageSyncStatus,
} from "@/app/store/controller/types";
import { ImageSyncStatus } from "@/app/store/controller/types";
import type {
ControllerVersions,
ControllerDetails,
Expand Down Expand Up @@ -81,18 +78,14 @@ const getImageSyncStatus = (
};

const getVersionDisplay = (versions: ControllerVersions) => {
const { current, install_type, origin } = versions;
const isDeb = install_type === ControllerInstallType.DEB;
const isSnap = install_type === ControllerInstallType.SNAP;
const { current, origin } = versions;
return (
<>
<span aria-label={Labels.Version}>
Version: {current.version || "Unknown (less than 2.3.0)"}
</span>
<br />
<span aria-label={Labels.Origin}>
{isDeb ? "Deb" : isSnap ? "Channel" : "Origin"}: {origin || "Unknown"}
</span>
<span aria-label={Labels.Origin}>Channel: {origin || "Unknown"}</span>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { VersionColumn } from "./VersionColumn";

import { ControllerInstallType } from "@/app/store/controller/types";
import * as factory from "@/testing/factories";
import { renderWithProviders, screen, userEvent } from "@/testing/utils";

Expand Down Expand Up @@ -33,17 +32,6 @@ describe("VersionColumn", () => {
expect(screen.getByTestId("origin")).toHaveTextContent("latest/edge");
});

it("can display the origin when it is a deb", async () => {
controller.versions = factory.controllerVersions({
install_type: ControllerInstallType.DEB,
origin: "stable",
});
renderWithProviders(<VersionColumn controller={controller} />);
expect(screen.getByTestId("origin")).toHaveTextContent(/Deb/);
await userEvent.click(screen.getByRole("button", { name: /information/i }));
expect(screen.getByRole("tooltip")).toHaveTextContent("stable");
});

it("can display a cohort tooltip", async () => {
controller.versions = factory.controllerVersions({
snap_cohort:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const VersionColumn = ({
}
const origin = versions.origin || null;
const cohortTooltip = cohortKey ? `Cohort key: \n${cohortKey}` : null;
const isDeb = versions.install_type === "deb";
return (
<DoubleRow
primary={
Expand All @@ -38,12 +37,8 @@ export const VersionColumn = ({
primaryTitle={versions.current.version}
secondary={
<>
<span data-testid="origin">
{!!origin && <>{isDeb ? "Deb" : origin} </>}
</span>
{!!(cohortTooltip || isDeb) && (
<TooltipButton message={isDeb ? origin : cohortTooltip} />
)}
<span data-testid="origin">{!!origin && <>{origin} </>}</span>
{!!cohortTooltip && <TooltipButton message={cohortTooltip} />}
</>
}
/>
Expand Down
6 changes: 2 additions & 4 deletions src/app/images/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ export const MAAS_IO_URLS = {
candidate: "http://images.maas.io/ephemeral-v3/candidate",
} as const;

export const MAAS_IO_DEFAULT_KEYRING_FILE_PATHS = {
deb: "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",
snap: "/snap/maas/current/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",
};
export const MAAS_IO_DEFAULT_KEYRING_FILE_PATH =
"/snap/maas/current/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg";

export const MAAS_IO_DEFAULTS = {
url: MAAS_IO_URLS.stable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { expect, it } from "vitest";

import { MAAS_IO_DEFAULT_KEYRING_FILE_PATHS } from "@/app/images/constants";
import { MAAS_IO_DEFAULT_KEYRING_FILE_PATH } from "@/app/images/constants";
import AddSource from "@/app/settings/views/Images/Sources/components/AddSource/AddSource";
import { Labels } from "@/app/settings/views/Images/Sources/constants";
import * as factory from "@/testing/factories";
import { imageSourceResolvers } from "@/testing/resolvers/imageSources";
import {
userEvent,
Expand Down Expand Up @@ -54,10 +53,10 @@ describe("AddSource", () => {
it("clears the other field when switching between keyring types", async () => {
renderWithProviders(<AddSource />);

// The default keyring filename is the snap path when no install type is set
// The default keyring filename is the snap path
expect(
screen.getByRole("textbox", { name: Labels.KeyringFilename })
).toHaveValue(MAAS_IO_DEFAULT_KEYRING_FILE_PATHS.snap);
).toHaveValue(MAAS_IO_DEFAULT_KEYRING_FILE_PATH);

// Switch to keyring_data
const select = screen.getByRole("combobox");
Expand All @@ -75,30 +74,12 @@ describe("AddSource", () => {
expect(screen.getByRole("textbox", { name: Labels.Url })).toHaveValue("");
});

it("pre-populates custom source with correct default keyring based on install type", async () => {
const state = factory.rootState({
general: factory.generalState({
installType: factory.installTypeState({ data: "deb" }),
}),
});
// Test with deb install type
const { rerender } = renderWithProviders(<AddSource />, {
state,
});

// Verify deb default keyring is shown
expect(
screen.getByRole("textbox", { name: Labels.KeyringFilename })
).toHaveValue(MAAS_IO_DEFAULT_KEYRING_FILE_PATHS.deb);

// Test with snap install type
state.general.installType = factory.installTypeState({ data: "snap" });
rerender(<AddSource />, { state });
it("pre-populates custom source with the snap default keyring", async () => {
renderWithProviders(<AddSource />);

// Verify snap default keyring is shown
expect(
screen.getByRole("textbox", { name: Labels.KeyringFilename })
).toHaveValue(MAAS_IO_DEFAULT_KEYRING_FILE_PATHS.snap);
).toHaveValue(MAAS_IO_DEFAULT_KEYRING_FILE_PATH);
});

it("does not display keyring fields when unsigned keyring type is selected", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { ReactElement } from "react";
import React, { useEffect, useState } from "react";
import React, { useState } from "react";

import { useSidePanel } from "@canonical/maas-react-components";
import { Select, Textarea } from "@canonical/react-components";
import type { FormikContextType } from "formik";
import { useDispatch, useSelector } from "react-redux";
import * as Yup from "yup";

import {
Expand All @@ -19,10 +18,8 @@ import type {
import FormikField from "@/app/base/components/FormikField";
import { FormikFieldChangeError } from "@/app/base/components/FormikField/FormikField";
import FormikForm from "@/app/base/components/FormikForm";
import { MAAS_IO_DEFAULT_KEYRING_FILE_PATHS } from "@/app/images/constants";
import { MAAS_IO_DEFAULT_KEYRING_FILE_PATH } from "@/app/images/constants";
import { Labels } from "@/app/settings/views/Images/Sources/constants";
import { generalActions } from "@/app/store/general";
import { installType } from "@/app/store/general/selectors";

export const SourceSchema = Yup.object()
.shape({
Expand All @@ -49,7 +46,6 @@ export type SourceValues = BootSourceCreateRequest & {
};

const AddSource = (): ReactElement => {
const dispatch = useDispatch();
const { closeSidePanel } = useSidePanel();
const [isValidated, setIsValidated] = useState(false);
const [lastValidatedValues, setLastValidatedValues] =
Expand All @@ -58,12 +54,6 @@ const AddSource = (): ReactElement => {
const createSource = useCreateImageSource();
const fetchImageSource = useFetchImageSource();

const installTypeData = useSelector(installType.get);

useEffect(() => {
dispatch(generalActions.fetchInstallType());
});

const onValidate = async (values: SourceValues) => {
if (!isValidated) {
try {
Expand Down Expand Up @@ -127,10 +117,7 @@ const AddSource = (): ReactElement => {
name: "",
url: "",
keyring_type: "keyring_filename",
keyring_filename:
installTypeData === "deb"
? MAAS_IO_DEFAULT_KEYRING_FILE_PATHS.deb
: MAAS_IO_DEFAULT_KEYRING_FILE_PATHS.snap,
keyring_filename: MAAS_IO_DEFAULT_KEYRING_FILE_PATH,
keyring_data: "",
skip_keyring_verification: undefined,
priority: 10,
Expand Down
2 changes: 0 additions & 2 deletions src/app/store/controller/types/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
ControllerInstallType,
ControllerMeta,
ControllerVersionIssues,
ImageSyncStatus,
Expand Down Expand Up @@ -45,7 +44,6 @@ export type ControllerVersionInfo = {

export type ControllerVersions = {
current: ControllerVersionInfo;
install_type?: ControllerInstallType;
origin: string;
snap_cohort?: string;
up_to_date: boolean;
Expand Down
6 changes: 0 additions & 6 deletions src/app/store/controller/types/enum.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export enum ControllerInstallType {
UNKNOWN = "",
SNAP = "snap",
DEB = "deb",
}

export enum ControllerMeta {
MODEL = "controller",
PK = "system_id",
Expand Down
1 change: 0 additions & 1 deletion src/app/store/controller/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type {
} from "./base";

export {
ControllerInstallType,
ControllerMeta,
ControllerVersionIssues,
ImageSyncStatus,
Expand Down
6 changes: 0 additions & 6 deletions src/app/store/general/reducers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ describe("general reducer", () => {
loaded: false,
loading: false,
},
installType: {
data: "",
errors: null,
loaded: false,
loading: false,
},
generatedCertificate: {
data: null,
errors: null,
Expand Down
Loading
Loading