Skip to content

Commit

Permalink
FD-631 uniconfig 6.0.0 related fixes (#413)
Browse files Browse the repository at this point in the history
* uniconfig 6.0.0 related fixes

* multiple install fix
  • Loading branch information
soson authored Mar 14, 2024
1 parent 19a9abe commit 7498362
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 240 deletions.
130 changes: 18 additions & 112 deletions src/external-api/network-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,53 +73,26 @@ export function decodeUniconfigConfigInput(value: unknown): UniconfigConfigInput

const UniconfigCommitInputValidator = t.type({
input: t.type({
'target-nodes': t.type({
node: t.array(t.string),
}),
'do-confirmed-commit': t.boolean,
'do-rollback': t.boolean,
'skip-unreachable-nodes': t.boolean,
'do-validate': t.boolean,
}),
});
export type UniconfigCommitInput = t.TypeOf<typeof UniconfigCommitInputValidator>;

const UniconfigDryRunCommitInputValidator = t.type({
input: t.type({
'do-rollback': t.boolean,
}),
});
export type UniconfigDryRunCommitInput = t.TypeOf<typeof UniconfigDryRunCommitInputValidator>;

export function decodeUniconfigCommitInput(value: unknown): UniconfigCommitInput {
return extractResult(UniconfigCommitInputValidator.decode(value));
}

const UniconfigStatusValidator = t.union([t.literal('complete'), t.literal('fail')]);
const UniconfigCommitOutputValidator = t.type({
output: t.union([
t.type({}),
t.type({
'overall-status': t.literal('complete'),
'node-results': t.type({
'node-result': t.array(
t.type({
'node-id': t.string,
'configuration-status': t.literal('complete'),
}),
),
}),
}),
t.type({
'overall-status': t.literal('fail'),
'node-results': t.type({
'node-result': t.array(
t.type({
'node-id': t.string,
'error-type': optional(t.string),
'error-message': optional(t.string),
'configuration-status': t.literal('fail'),
'rollback-status': optional(UniconfigStatusValidator),
}),
),
}),
}),
]),
});
export type UniconfigCommitOutput = t.TypeOf<typeof UniconfigCommitOutputValidator>;

export function decodeUniconfigCommitOutput(value: unknown): UniconfigCommitOutput {
return extractResult(UniconfigCommitOutputValidator.decode(value));
}

const UniconfigDryRunCommitOutputValidator = t.type({
output: t.union([
Expand Down Expand Up @@ -170,17 +143,6 @@ export function decodeUniconfigReplaceInput(value: unknown): UniconfigReplaceInp
return extractResult(UniconfigReplaceInputValidator.decode(value));
}

const UniconfigReplaceOutputValidator = t.type({
output: t.type({
'overall-status': UniconfigStatusValidator,
}),
});
export type UniconfigReplaceOutput = t.TypeOf<typeof UniconfigReplaceOutputValidator>;

export function decodeUniconfigReplaceOutput(value: unknown): UniconfigReplaceOutput {
return extractResult(UniconfigReplaceOutputValidator.decode(value));
}

const UniconfigSnapshotsOutputValidator = t.type({
'snapshots-metadata': t.union([
t.type({}),
Expand Down Expand Up @@ -214,16 +176,6 @@ export type UniconfigSnapshotInput = t.TypeOf<typeof UniconfigSnapshotInputValid
export function decodeUniconfigSnapshotInput(value: unknown): UniconfigSnapshotInput {
return extractResult(UniconfigSnapshotInputValidator.decode(value));
}
const UniconfigSnapshotOutputValidator = t.type({
output: t.type({
'overall-status': UniconfigStatusValidator,
}),
});
export type UniconfigSnapshotOutput = t.TypeOf<typeof UniconfigSnapshotOutputValidator>;

export function decodeUniconfigSnapshotOutput(value: unknown): UniconfigSnapshotOutput {
return extractResult(UniconfigSnapshotOutputValidator.decode(value));
}

const UniconfigApplySnapshotInputValidator = t.type({
input: t.type({
Expand All @@ -239,17 +191,6 @@ export function decodeUniconfigApplySnapshotInput(value: unknown): UniconfigAppl
return extractResult(UniconfigApplySnapshotInputValidator.decode(value));
}

const UniconfigApplySnapshotOutputValidator = t.type({
output: t.type({
'overall-status': UniconfigStatusValidator,
}),
});
export type UniconfigApplySnapshotOutput = t.TypeOf<typeof UniconfigApplySnapshotOutputValidator>;

export function decodeUniconfigApplySnapshotOutput(value: unknown): UniconfigApplySnapshotOutput {
return extractResult(UniconfigApplySnapshotOutputValidator.decode(value));
}

const UniconfigDiffInputValidator = t.type({
input: t.type({
'target-nodes': t.type({
Expand Down Expand Up @@ -284,12 +225,9 @@ const UniconfigDiffOutputValidator = t.type({
),
),
'created-data': optional(t.array(DiffDataValidator)),
status: UniconfigStatusValidator,
}),
),
}),
'error-message': optional(t.string),
'overall-status': UniconfigStatusValidator,
}),
});
export type UniconfigDiffOutput = t.TypeOf<typeof UniconfigDiffOutputValidator>;
Expand All @@ -298,41 +236,21 @@ export function decodeUniconfigDiffOuptut(value: unknown): UniconfigDiffOutput {
return extractResult(UniconfigDiffOutputValidator.decode(value));
}

const SnapshotMetadata = t.type({
name: t.string,
nodes: t.array(t.string),
'creation-time': t.string,
});

const UniconfigSyncInputValidator = t.type({
input: t.type({
'target-nodes': t.type({
node: t.array(t.string),
}),
}),
snapshot: t.array(SnapshotMetadata),
});
export type UniconfigSyncInput = t.TypeOf<typeof UniconfigSyncInputValidator>;

export function decodeUniconfigSyncInput(value: unknown): UniconfigSyncInput {
return extractResult(UniconfigSyncInputValidator.decode(value));
}

const UniconfigSyncOutputValidator = t.type({
output: t.type({
'error-message': optional(t.string),
'overall-status': UniconfigStatusValidator,
'node-results': t.type({
'node-result': t.array(
t.type({
'node-id': t.string,
status: UniconfigStatusValidator,
'error-type': optional(t.union([t.literal('no-connection'), t.literal('processing-error')])),
'error-message': optional(t.string),
}),
),
}),
}),
});
export type UniconfigSyncOutput = t.TypeOf<typeof UniconfigSyncOutputValidator>;

export function decodeUniconfigSyncOutput(value: unknown): UniconfigSyncOutput {
return extractResult(UniconfigSyncOutputValidator.decode(value));
}

const UniconfigInstallOutputTypeValidator = t.type({
errors: t.type({
error: t.array(
Expand Down Expand Up @@ -391,18 +309,6 @@ export type UniconfigDeleteSnapshotParams = {
};
};

const UniconfigDeleteSnapshotOutputValidator = t.type({
output: t.type({
'error-message': optional(t.string),
'overall-status': UniconfigStatusValidator,
}),
});
export type UniconfigDeleteSnapshotOutput = t.TypeOf<typeof UniconfigDeleteSnapshotOutputValidator>;

export function decodeUniconfigDeleteSnapshotOutput(value: unknown): UniconfigDeleteSnapshotOutput {
return extractResult(UniconfigDeleteSnapshotOutputValidator.decode(value));
}

const SuccessTransaction = t.type({
'transaction-id': t.string,
status: t.literal('SUCCESS'),
Expand Down
11 changes: 5 additions & 6 deletions src/external-api/uniconfig-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,12 @@ export async function installMultipleDevicesCache({
}): Promise<void> {
const uniconfigCache = UniconfigCache.getInstance();
const url = await uniconfigURL;
const response = await installMultipleDevices(url, devicesToInstall);

response.output['node-results']?.forEach((nodeResult) => {
if (nodeResult.status === 'fail') {
throw new Error(nodeResult['error-message'] ?? 'could not install device');
}
});
try {
await installMultipleDevices(url, devicesToInstall);
} catch {
throw new Error('could not install device');
}

deviceNames.forEach((deviceName) => uniconfigCache.delete(url, deviceName));
}
Expand Down
72 changes: 16 additions & 56 deletions src/external-api/uniconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,33 @@ import {
CheckInstalledNodesOutput,
decodeInstalledDevicesOutput,
decodeInstalledNodeOutput,
decodeUniconfigApplySnapshotOutput,
decodeUniconfigCommitOutput,
decodeUniconfigConfigOutput,
decodeUniconfigDeleteSnapshotOutput,
decodeUniconfigDiffOuptut,
decodeUniconfigDryRunCommitOutput,
decodeUniconfigExternalStorageOutput,
decodeUniconfigInstallOutput,
decodeUniconfigMultipleNodesOutput,
decodeUniconfigReplaceOutput,
decodeUniconfigRevertChangesOutput,
decodeUniconfigSnapshotOutput,
decodeUniconfigSnapshotsOutput,
decodeUniconfigSyncOutput,
decodeUniconfigTransactionLogOutput,
InstalledDevicesOutput,
RevertChangesInput,
UniconfigApplySnapshotInput,
UniconfigApplySnapshotOutput,
UniconfigCommitInput,
UniconfigCommitOutput,
UniconfigConfigInput,
UniconfigConfigOutput,
UniconfigDeleteSnapshotOutput,
UniconfigDeleteSnapshotParams,
UniconfigDiffInput,
UniconfigDiffOutput,
UniconfigDryRunCommitInput,
UniconfigDryRunCommitOutput,
UniconfigInstallOutput,
UniconfigMultipleNodesOutput,
UniconfigReplaceInput,
UniconfigReplaceOutput,
UniconfigRevertChangesOutput,
UniconfigSnapshotInput,
UniconfigSnapshotOutput,
UniconfigSnapshotsOutput,
UniconfigSyncInput,
UniconfigSyncOutput,
UniconfigTransactionLogOutput,
UninstallDeviceInput,
UninstallMultipleDevicesInput,
Expand Down Expand Up @@ -93,11 +82,8 @@ export async function getCheckInstalledDevices(
return data;
}

export async function installMultipleDevices(baseURL: string, input: unknown): Promise<UniconfigMultipleNodesOutput> {
const json = await sendPostRequest([baseURL, '/operations/connection-manager:install-multiple-nodes'], input);
const data = decodeUniconfigMultipleNodesOutput(json);

return data;
export async function installMultipleDevices(baseURL: string, input: unknown): Promise<void> {
await sendPostRequest([baseURL, '/operations/connection-manager:install-multiple-nodes'], input);
}

export async function uninstallMultipleDevices(
Expand Down Expand Up @@ -172,17 +158,14 @@ export async function postCommitToNetwork(
baseURL: string,
params: UniconfigCommitInput,
transactionId: string,
): Promise<UniconfigCommitOutput> {
): Promise<void> {
const cookie = makeCookieFromTransactionId(transactionId);
const json = await sendPostRequest([baseURL, '/operations/uniconfig-manager:commit'], params, cookie);
const data = decodeUniconfigCommitOutput(json);

return data;
await sendPostRequest([baseURL, '/operations/uniconfig-manager:commit'], params, cookie);
}

export async function postDryRunCommitToNetwork(
baseURL: string,
params: UniconfigCommitInput,
params: UniconfigDryRunCommitInput,
transactionId: string,
): Promise<UniconfigDryRunCommitOutput> {
const cookie = makeCookieFromTransactionId(transactionId);
Expand All @@ -196,16 +179,9 @@ export async function replaceConfig(
baseURL: string,
params: UniconfigReplaceInput,
transactionId: string,
): Promise<UniconfigReplaceOutput> {
): Promise<void> {
const cookie = makeCookieFromTransactionId(transactionId);
const json = await sendPostRequest(
[baseURL, '/operations/uniconfig-manager:replace-config-with-operational'],
params,
cookie,
);
const data = decodeUniconfigReplaceOutput(json);

return data;
await sendPostRequest([baseURL, '/operations/uniconfig-manager:replace-config-with-operational'], params, cookie);
}

export async function getSnapshots(baseURL: string, transactionId: string): Promise<UniconfigSnapshotsOutput> {
Expand All @@ -220,28 +196,18 @@ export async function createSnapshot(
baseURL: string,
params: UniconfigSnapshotInput,
transactionId: string,
): Promise<UniconfigSnapshotOutput> {
): Promise<void> {
const cookie = makeCookieFromTransactionId(transactionId);
const json = await sendPostRequest([baseURL, '/operations/snapshot-manager:create-snapshot'], params, cookie);
const data = decodeUniconfigSnapshotOutput(json);

return data;
await sendPostRequest([baseURL, '/operations/snapshot-manager:create-snapshot'], params, cookie);
}

export async function applySnapshot(
baseURL: string,
params: UniconfigApplySnapshotInput,
transactionId: string,
): Promise<UniconfigApplySnapshotOutput> {
): Promise<void> {
const cookie = makeCookieFromTransactionId(transactionId);
const json = await sendPostRequest(
[baseURL, '/operations/snapshot-manager:replace-config-with-snapshot'],
params,
cookie,
);
const data = decodeUniconfigApplySnapshotOutput(json);

return data;
await sendPostRequest([baseURL, '/operations/snapshot-manager:replace-config-with-snapshot'], params, cookie);
}

export async function getCalculatedDiff(
Expand All @@ -260,24 +226,18 @@ export async function syncFromNetwork(
baseURL: string,
params: UniconfigSyncInput,
transactionId: string,
): Promise<UniconfigSyncOutput> {
): Promise<void> {
const cookie = makeCookieFromTransactionId(transactionId);
const json = await sendPostRequest([baseURL, '/operations/uniconfig-manager:sync-from-network'], params, cookie);
const data = decodeUniconfigSyncOutput(json);

return data;
await sendPostRequest([baseURL, '/operations/uniconfig-manager:sync-from-network'], params, cookie);
}

export async function deleteSnapshot(
baseURL: string,
params: UniconfigDeleteSnapshotParams,
transactionId: string,
): Promise<UniconfigDeleteSnapshotOutput> {
): Promise<void> {
const cookie = makeCookieFromTransactionId(transactionId);
const json = await sendPostRequest([baseURL, 'operations/snapshot-manager:delete-snapshot'], params, cookie);
const data = decodeUniconfigDeleteSnapshotOutput(json);

return data;
await sendPostRequest([baseURL, 'operations/snapshot-manager:delete-snapshot'], params, cookie);
}

async function createTransaction(baseURL: string): Promise<string> {
Expand Down
1 change: 0 additions & 1 deletion src/schema/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ input ApplySnapshotInput {

type ApplySnapshotPayload {
isOk: Boolean!
output: String!
}

interface BaseGraphNode {
Expand Down
Loading

0 comments on commit 7498362

Please sign in to comment.