Skip to content

Commit

Permalink
[sonic-package-manager] Increate timeout for sonic-package-manager mi…
Browse files Browse the repository at this point in the history
…grate (sonic-net#2973)

What I did
When we migrate package via sonic-package-manager in some low-performance device, getting docker image from old image via docker socket may timeout by default timeout setting (60s) client.py. This PR is to increase timeout to 120s.

How I did it
Increase docker client timeout from 60s to 120s.

How to verify it
ut passed.
Build image with INCLUDE_MACSEC, and install it, macsec image was not include. And the build image with this PR, install it. Migrate package successfully.

Signed-off-by: Yaqiang Zhu <yaqiangzhu@microsoft.com>
  • Loading branch information
yaqiangz authored Sep 11, 2023
1 parent 57b3b31 commit b1ac2ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sonic_package_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,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 @@ -701,7 +705,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
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 @@ -356,3 +356,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)

0 comments on commit b1ac2ef

Please sign in to comment.