Skip to content

Commit 9fd75b5

Browse files
committed
Add prefix to images for ONIE installer to define explicit ordering
1 parent b116154 commit 9fd75b5

File tree

1 file changed

+22
-3
lines changed
  • platform/mellanox/mlnx-platform-api/sonic_platform

1 file changed

+22
-3
lines changed

platform/mellanox/mlnx-platform-api/sonic_platform/component.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
else:
3535
import ConfigParser as configparser
3636

37+
from shutil import copyfile
38+
3739
from sonic_platform_base.component_base import ComponentBase, \
3840
FW_AUTO_INSTALLED, \
3941
FW_AUTO_UPDATED, \
@@ -133,6 +135,18 @@ class ONIEUpdater(object):
133135

134136
ONIE_IMAGE_INFO_COMMAND = '/bin/bash {} -q -i'
135137

138+
BIOS_UPDATE_FILE_EXT = '.rom'
139+
140+
def __add_prefix(self, image_path):
141+
if self.BIOS_UPDATE_FILE_EXT not in image_path:
142+
rename_path = "/tmp/00-{}".format(os.path.basename(image_path))
143+
else:
144+
rename_path = "/tmp/99-{}".format(os.path.basename(image_path))
145+
146+
copyfile(image_path, rename_path)
147+
148+
return rename_path
149+
136150
def __mount_onie_fs(self):
137151
fs_mountpoint = '/mnt/onie-fs'
138152
onie_path = '/lib/onie'
@@ -170,15 +184,19 @@ def __umount_onie_fs(self):
170184
os.rmdir(fs_mountpoint)
171185

172186
def __stage_update(self, image_path):
173-
cmd = self.ONIE_FW_UPDATE_CMD_ADD.format(image_path)
187+
rename_path = self.__add_prefix(image_path)
188+
189+
cmd = self.ONIE_FW_UPDATE_CMD_ADD.format(rename_path)
174190

175191
try:
176192
subprocess.check_call(cmd.split(), universal_newlines=True)
177193
except subprocess.CalledProcessError as e:
178194
raise RuntimeError("Failed to stage firmware update: {}".format(str(e)))
179195

180196
def __unstage_update(self, image_path):
181-
cmd = self.ONIE_FW_UPDATE_CMD_REMOVE.format(os.path.basename(image_path))
197+
rename_path = self.__add_prefix(image_path)
198+
199+
cmd = self.ONIE_FW_UPDATE_CMD_REMOVE.format(os.path.basename(rename_path))
182200

183201
try:
184202
subprocess.check_call(cmd.split(), universal_newlines=True)
@@ -206,7 +224,8 @@ def __is_update_staged(self, image_path):
206224
except subprocess.CalledProcessError as e:
207225
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
208226

209-
basename = os.path.basename(image_path)
227+
rename_path = self.__add_prefix(image_path)
228+
basename = os.path.basename(rename_path)
210229

211230
for line in output.splitlines():
212231
if line.startswith(basename):

0 commit comments

Comments
 (0)