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

[code sync] Merge code from sonic-net/sonic-utilities:202205 to 202205 #29

Merged
merged 3 commits into from
Sep 27, 2023
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
10 changes: 8 additions & 2 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,10 @@ def download_firmware(port_name, filepath):
sys.exit(EXIT_FAIL)

# Increase the optoe driver's write max to speed up firmware download
sfp.set_optoe_write_max(SMBUS_BLOCK_WRITE_SIZE)
try:
sfp.set_optoe_write_max(SMBUS_BLOCK_WRITE_SIZE)
except NotImplementedError:
click.echo("Platform doesn't implement optoe write max change. Skipping value increase.")

with click.progressbar(length=file_size, label="Downloading ...") as bar:
address = 0
Expand All @@ -1388,7 +1391,10 @@ def download_firmware(port_name, filepath):
remaining -= count

# Restore the optoe driver's write max to '1' (default value)
sfp.set_optoe_write_max(1)
try:
sfp.set_optoe_write_max(1)
except NotImplementedError:
click.echo("Platform doesn't implement optoe write max change. Skipping value restore!")

status = api.cdb_firmware_download_complete()
update_firmware_info_to_state_db(port_name)
Expand Down
7 changes: 6 additions & 1 deletion sonic_package_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ def reset(self, name: str, force: bool = False, skip_host_plugins: bool = False)
allow_downgrade=True,
skip_host_plugins=skip_host_plugins)

@under_lock
def get_docker_client(self, dockerd_sock:str):
return docker.DockerClient(base_url=f'unix://{dockerd_sock}', timeout=120)

@under_lock
def migrate_packages(self,
old_package_database: PackageDatabase,
Expand Down Expand Up @@ -695,7 +699,8 @@ def migrate_package(old_package_entry,
# dockerd_sock is defined, so use docked_sock to connect to
# dockerd and fetch package image from it.
log.info(f'installing {name} from old docker library')
docker_api = DockerApi(docker.DockerClient(base_url=f'unix://{dockerd_sock}'))
docker_client = self.get_docker_client(dockerd_sock)
docker_api = DockerApi(docker_client)

image = docker_api.get_image(old_package_entry.image_id)

Expand Down
17 changes: 17 additions & 0 deletions tests/sfputil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,23 @@ def test_show_fwversion_Rj45(self, mock_chassis):
assert result.output == 'Show firmware version is not applicable for RJ45 port Ethernet0.\n'
assert result.exit_code == EXIT_FAIL

@patch('builtins.open')
@patch('sfputil.main.platform_chassis')
@patch('sfputil.main.logical_port_to_physical_port_index', MagicMock(return_value=1))
@patch('sfputil.main.update_firmware_info_to_state_db', MagicMock())
def test_download_firmware(self, mock_chassis, mock_file):
mock_file.return_value.tell.return_value = 0
mock_sfp = MagicMock()
mock_api = MagicMock()
mock_sfp.get_xcvr_api = MagicMock(return_value=mock_api)
mock_chassis.get_sfp = MagicMock(return_value=mock_sfp)
mock_api.get_module_fw_mgmt_feature.return_value = {'status': True, 'feature': (0, 0, False, False, 0)}
mock_api.cdb_start_firmware_download.return_value = 1
mock_api.cdb_firmware_download_complete.return_value = 1
mock_sfp.set_optoe_write_max = MagicMock(side_effect=NotImplementedError)
status = sfputil.download_firmware("Ethernet0", "test.bin")
assert status == 1

@patch('sfputil.main.platform_chassis')
@patch('sfputil.main.logical_port_to_physical_port_index', MagicMock(return_value=1))
def test_run_firmwre(self, mock_chassis):
Expand Down
28 changes: 28 additions & 0 deletions tests/sonic_package_manager/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,31 @@ def test_manager_migration(package_manager, fake_db_for_migration):
call('test-package-6=2.0.0')],
any_order=True
)


def mock_get_docker_client(dockerd_sock):
class DockerClient:
def __init__(self, dockerd_sock):
class Image:
def __init__(self, image_id):
self.image_id = image_id

def save(self, named):
return ["named: {}".format(named).encode()]

image = Image("dummy_id")
self.images = {
"Azure/docker-test-3:1.6.0": image,
"Azure/docker-test-6:2.0.0": image
}
self.dockerd_sock = dockerd_sock

return DockerClient(dockerd_sock)


def test_manager_migration_dockerd(package_manager, fake_db_for_migration, mock_docker_api):
package_manager.install = Mock()
package_manager.get_docker_client = Mock(side_effect=mock_get_docker_client)
package_manager.migrate_packages(fake_db_for_migration, '/var/run/docker.sock')
package_manager.get_docker_client.assert_has_calls([
call('/var/run/docker.sock')], any_order=True)
Loading