Skip to content

Commit

Permalink
Move OS short name generator to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Ellis committed Apr 30, 2020
1 parent ba23801 commit efa9e46
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
28 changes: 16 additions & 12 deletions legacy/src/app/controllers/pods_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
* MAAS Pods List Controller
*/

const getOSShortName = (node, osInfo) => {
if (node) {
const baseString = `${node.osystem}/${node.distro_series}`;
const releaseArr = osInfo.releases.find(
(release) => release[0] === baseString
);
if (releaseArr && node.osystem === "ubuntu") {
return releaseArr[1].split('"')[0].trim(); // Remove "Adjective Animal"
}
return (releaseArr && releaseArr[1]) || baseString;
}
return "Unknown";
};

/* @ngInject */
function PodsListController(
$scope,
Expand Down Expand Up @@ -426,19 +440,9 @@ function PodsListController(
return item && item.name;
};

$scope.getOSInfo = (pod) => {
$scope.getPodOSName = (pod) => {
const podHost = $scope.hostMap.get(pod.id);
if (podHost) {
const baseString = `${podHost.osystem}/${podHost.distro_series}`;
const releaseArr = $scope.osInfo.releases.find(
(release) => release[0] === baseString
);
if (releaseArr && podHost.osystem === "ubuntu") {
return releaseArr[1].split('"')[0].trim(); // Remove "Adjective Animal"
}
return (releaseArr && releaseArr[1]) || baseString;
}
return "Unknown";
return getOSShortName(podHost, $scope.osInfo);
};

$scope.getPowerIconClass = (pod) => {
Expand Down
10 changes: 5 additions & 5 deletions legacy/src/app/controllers/tests/test_pods_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ describe("PodsListController", function() {
});
});

describe("getOSInfo", () => {
describe("getPodOSName", () => {
it("returns host's OS info", () => {
makeController();
const pod = { id: 1, host: "abc" };
Expand All @@ -828,7 +828,7 @@ describe("PodsListController", function() {
$scope.osInfo = {
releases: [["centos/centos70", "CentOS 7"]],
};
expect($scope.getOSInfo(pod)).toEqual("CentOS 7");
expect($scope.getPodOSName(pod)).toEqual("CentOS 7");
});

it("returns trimmed host OS info if OS is ubuntu", () => {
Expand All @@ -842,7 +842,7 @@ describe("PodsListController", function() {
$scope.osInfo = {
releases: [["ubuntu/bionic", 'Ubuntu 18.04 LTS "Bionic Beaver"']],
};
expect($scope.getOSInfo(pod)).toEqual("Ubuntu 18.04 LTS");
expect($scope.getPodOSName(pod)).toEqual("Ubuntu 18.04 LTS");
});

it("returns unformatted OS info if MAAS does not know about the release", () => {
Expand All @@ -856,13 +856,13 @@ describe("PodsListController", function() {
$scope.osInfo = {
releases: [["ubuntu/bionic", 'Ubuntu 18.04 LTS "Bionic Beaver"']],
};
expect($scope.getOSInfo(pod)).toEqual("ubuntu/focal");
expect($scope.getPodOSName(pod)).toEqual("ubuntu/focal");
});

it("returns unknown if the pod does not have a host", () => {
makeController();
const pod = { id: 1, host: undefined };
expect($scope.getOSInfo(pod)).toEqual("Unknown");
expect($scope.getPodOSName(pod)).toEqual("Unknown");
});
});
});
2 changes: 1 addition & 1 deletion legacy/src/app/partials/pods-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ <h3 class="p-heading-icon__title p-heading--four u-no-max-width u-sv3">You have
<td class="p-table__cell p-double-row" aria-label="Operating system" title="OS">
<div class="p-double-row">
<div class="p-double-row__main-row">
<span class="u-text-overflow" title="{$ getOSInfo(pod) $}">{$ getOSInfo(pod) $}</span>
<span class="u-text-overflow" title="{$ getPodOSName(pod) $}">{$ getPodOSName(pod) $}</span>
</div>
</div>
</td>
Expand Down

0 comments on commit efa9e46

Please sign in to comment.