Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Platform][AS5835-54T][AS5835-54X][AS7326-56X]: Add platform component API: install_firmware #213

Merged
merged 1 commit into from
Sep 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

try:
import subprocess
import os
import json
from sonic_platform_base.component_base import ComponentBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -112,7 +115,36 @@ def install_firmware(self, image_path):
Returns:
A boolean, True if install successfully, False if not
"""
raise NotImplementedError
ret, output = getstatusoutput_noshell(["tar", "-C", "/tmp", "-xzf", image_path ] )
if ret != 0:
print("Installation failed because of wrong image package")
return False

if False == os.path.exists("/tmp/install.json"):
print("Installation failed without jsonfile")
return False

input_file = open ('/tmp/install.json')
json_array = json.load(input_file)
ret = 1
for item in json_array:
if item.get('id') == None or item.get('path') == None:
continue
if self.name == item['id'] and item['path'] and item.get('cpu'):
print( "Find", item['id'], item['path'], item['cpu'] )
ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'], item['cpu'] ])
if ret == 0:
break
elif self.name == item['id'] and item['path']:
print( "Find", item['id'], item['path'] )
ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'] ])
if ret == 0:
break

if ret == 0:
return True
else:
return False

def get_presence(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

try:
import subprocess
import os
import json
from sonic_platform_base.component_base import ComponentBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -100,7 +103,36 @@ def install_firmware(self, image_path):
Returns:
A boolean, True if install successfully, False if not
"""
raise NotImplementedError
ret, output = getstatusoutput_noshell(["tar", "-C", "/tmp", "-xzf", image_path ] )
if ret != 0:
print("Installation failed because of wrong image package")
return False

if False == os.path.exists("/tmp/install.json"):
print("Installation failed without jsonfile")
return False

input_file = open ('/tmp/install.json')
json_array = json.load(input_file)
ret = 1
for item in json_array:
if item.get('id') == None or item.get('path') == None:
continue
if self.name == item['id'] and item['path'] and item.get('cpu'):
print( "Find", item['id'], item['path'], item['cpu'] )
ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'], item['cpu'] ])
if ret == 0:
break
elif self.name == item['id'] and item['path']:
print( "Find", item['id'], item['path'] )
ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'] ])
if ret == 0:
break

if ret == 0:
return True
else:
return False

def get_presence(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

try:
import subprocess
import os
import json
from sonic_platform_base.component_base import ComponentBase
from sonic_py_common.general import getstatusoutput_noshell
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -100,7 +103,36 @@ def install_firmware(self, image_path):
Returns:
A boolean, True if install successfully, False if not
"""
raise NotImplementedError
ret, output = getstatusoutput_noshell(["tar", "-C", "/tmp", "-xzf", image_path ] )
if ret != 0:
print("Installation failed because of wrong image package")
return False

if False == os.path.exists("/tmp/install.json"):
print("Installation failed without jsonfile")
return False

input_file = open ('/tmp/install.json')
json_array = json.load(input_file)
ret = 1
for item in json_array:
if item.get('id') == None or item.get('path') == None:
continue
if self.name == item['id'] and item['path'] and item.get('cpu'):
print( "Find", item['id'], item['path'], item['cpu'] )
ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'], item['cpu'] ])
if ret == 0:
break
elif self.name == item['id'] and item['path']:
print( "Find", item['id'], item['path'] )
ret, output = getstatusoutput_noshell(["/tmp/run_install.sh", item['id'], item['path'] ])
if ret == 0:
break

if ret == 0:
return True
else:
return False

def get_presence(self):
"""
Expand Down