Skip to content

Commit 15050b8

Browse files
yoshiemuranakarfrandse
authored andcommitted
Refactor firmware store to get backup from SoftwareImages
Eliminates an extra call to find the system backup firmware image. Signed-off-by: Yoshie Muranaka <[email protected]> Change-Id: I82e36c6b8982dc3bfbdfb57c9ee143c1367e7c9e
1 parent 5a57d4b commit 15050b8

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

src/store/modules/Configuration/FirmwareStore.js

+29-32
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,40 @@ const FirmwareStore = {
3939
setApplyTime: (state, applyTime) => (state.applyTime = applyTime)
4040
},
4141
actions: {
42-
async getSystemFirwareVersion({ commit, state }) {
42+
async getSystemFirwareVersion({ commit }) {
4343
return await api
4444
.get('/redfish/v1/Managers/bmc')
45-
.then(({ data: { Links: { ActiveSoftwareImage } } }) => {
46-
const location = ActiveSoftwareImage['@odata.id'];
47-
return api.get(location);
45+
.then(({ data: { Links } }) => {
46+
const currentLocation = Links.ActiveSoftwareImage['@odata.id'];
47+
// Check SoftwareImages list for not ActiveSoftwareImage id
48+
const backupLocation = Links.SoftwareImages.map(
49+
item => item['@odata.id']
50+
).find(location => {
51+
const id = location.split('/').pop();
52+
const currentId = currentLocation.split('/').pop();
53+
return id !== currentId;
54+
});
55+
return { currentLocation, backupLocation };
4856
})
49-
.then(({ data }) => {
50-
const version = data.Version;
51-
const id = data.Id;
52-
const location = data['@odata.id'];
53-
commit('setActiveFirmware', { version, id, location });
54-
// TODO: temporary workaround to get 'Backup' Firmware
55-
// information
56-
return api.get('/redfish/v1/UpdateService/FirmwareInventory');
57-
})
58-
.then(({ data: { Members } }) => {
59-
// TODO: temporary workaround to get 'Backup' Firmware
60-
// information
61-
// Check FirmwareInventory list for not ActiveSoftwareImage id
62-
const backupLocation = Members.map(item => item['@odata.id']).find(
63-
location => {
64-
const id = location.split('/').pop();
65-
return id !== state.activeFirmware.id;
66-
}
67-
);
57+
.then(async ({ currentLocation, backupLocation }) => {
58+
const currentData = await api.get(currentLocation);
59+
let backupData = {};
60+
6861
if (backupLocation) {
69-
return api.get(backupLocation);
62+
backupData = await api.get(backupLocation);
7063
}
71-
})
72-
.then(({ data } = {}) => {
73-
if (!data) return;
74-
const version = data.Version;
75-
const id = data.Id;
76-
const location = data['@odata.id'];
77-
const status = data.Status ? data.Status.State : '--';
78-
commit('setBackupFirmware', { version, id, location, status });
64+
65+
commit('setActiveFirmware', {
66+
version: currentData?.data?.Version,
67+
id: currentData?.data?.Id,
68+
location: currentData?.data?.['@odata.id']
69+
});
70+
commit('setBackupFirmware', {
71+
version: backupData.data?.Version,
72+
id: backupData.data?.Id,
73+
location: backupData.data?.['@odata.id'],
74+
status: backupData.data?.Status?.State
75+
});
7976
})
8077
.catch(error => console.log(error));
8178
},

0 commit comments

Comments
 (0)