def test_all(self): """Perform a lazy sync and change to immeditae to force download.""" # delete orphans to assure that no content units are present on the # file system delete_orphans() client = gen_file_client() artifacts_api = ArtifactsApi(core_client) repo_api = RepositoriesFileApi(client) remote_api = RemotesFileApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_file_remote(policy=choice(ON_DEMAND_DOWNLOAD_POLICIES)) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync the repository using a lazy download policy repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) artifacts = artifacts_api.list().to_dict()["results"] self.assertEqual(len(artifacts), 0, artifacts) # Update the policy to immediate response = remote_api.partial_update(remote.pulp_href, {"policy": "immediate"}) monitor_task(response.task) remote = remote_api.read(remote.pulp_href) self.assertEqual(remote.policy, "immediate") # Sync using immediate download policy repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) # Assert that missing artifacts are downloaded artifacts = artifacts_api.list().to_dict()["results"] self.assertEqual(len(artifacts), FILE_FIXTURE_COUNT, artifacts)
class CRUDRemoteTestCase(unittest.TestCase): """CRUD remotes.""" @classmethod def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() def setUp(self): self.client = FileApiClient(self.cfg.get_bindings_config()) self.remotes_api = RemotesFileApi(self.client) self.remote_attrs = { "name": utils.uuid4(), "url": FILE_FIXTURE_MANIFEST_URL, "ca_cert": None, "client_cert": None, "client_key": None, "tls_validation": False, "proxy_url": None, "username": "******", "password": "******", "download_concurrency": 10, "policy": "on_demand", "total_timeout": None, "connect_timeout": None, "sock_connect_timeout": None, "sock_read_timeout": None, } self.remote = self.remotes_api.create(self.remote_attrs) def _compare_results(self, data, received): self.assertFalse(hasattr(received, "password")) # handle write only fields data.pop("username", None) data.pop("password", None) data.pop("client_key", None) for k in data: self.assertEqual(getattr(received, k), data[k]) def test_read(self): # Compare initial-attrs vs remote created in setUp self._compare_results(self.remote_attrs, self.remote) def test_update(self): data = {"download_concurrency": 23, "policy": "immediate"} self.remotes_api.partial_update(self.remote.pulp_href, data) time.sleep(1) # without this, the read returns the pre-patch values new_remote = self.remotes_api.read(self.remote.pulp_href) self._compare_results(data, new_remote) def test_password_writeable(self): """Test that a password can be updated with a PUT request.""" cli_client = cli.Client(self.cfg) remote = self.remotes_api.create({"name": "test_pass", "url": "http://", "password": "******"}) href = remote.pulp_href uuid = re.search(r"/pulp/api/v3/remotes/file/file/([\w-]+)/", href).group(1) shell_cmd = ( f"import pulpcore; print(pulpcore.app.models.Remote.objects.get(pk='{uuid}').password)" ) self.addCleanup(self.remotes_api.delete, href) # test a PUT request with a new password remote_update = FileFileRemote(name="test_pass", url="http://", password="******") response = self.remotes_api.update(href, remote_update) monitor_task(response.task) exc = cli_client.run(["pulpcore-manager", "shell", "-c", shell_cmd]) self.assertEqual(exc.stdout.rstrip("\n"), "changed") def test_password_not_unset(self): """Test that password doesn't get unset when not passed with a PUT request.""" cli_client = cli.Client(self.cfg) remote = self.remotes_api.create({"name": "test_pass", "url": "http://", "password": "******"}) href = remote.pulp_href uuid = re.search(r"/pulp/api/v3/remotes/file/file/([\w-]+)/", href).group(1) shell_cmd = ( f"import pulpcore; print(pulpcore.app.models.Remote.objects.get(pk='{uuid}').password)" ) self.addCleanup(self.remotes_api.delete, href) # test a PUT request without a password remote_update = FileFileRemote(name="pass_test", url="http://") response = self.remotes_api.update(href, remote_update) monitor_task(response.task) exc = cli_client.run(["pulpcore-manager", "shell", "-c", shell_cmd]) self.assertEqual(exc.stdout.rstrip("\n"), "new") def test_timeout_attributes(self): # Test valid timeout settings (float >= 0) data = { "total_timeout": 1.0, "connect_timeout": 66.0, "sock_connect_timeout": 0.0, "sock_read_timeout": 3.1415926535, } self.remotes_api.partial_update(self.remote.pulp_href, data) time.sleep(1) new_remote = self.remotes_api.read(self.remote.pulp_href) self._compare_results(data, new_remote) def test_timeout_attributes_float_lt_zero(self): # Test invalid float < 0 data = { "total_timeout": -1.0, } with self.assertRaises(ApiException): self.remotes_api.partial_update(self.remote.pulp_href, data) def test_timeout_attributes_non_float(self): # Test invalid non-float data = { "connect_timeout": "abc", } with self.assertRaises(ApiException): self.remotes_api.partial_update(self.remote.pulp_href, data) def test_timeout_attributes_reset_to_empty(self): # Test reset to empty data = { "total_timeout": False, "connect_timeout": None, "sock_connect_timeout": False, "sock_read_timeout": None, } response = self.remotes_api.partial_update(self.remote.pulp_href, data) monitor_task(response.task) new_remote = self.remotes_api.read(self.remote.pulp_href) self._compare_results(data, new_remote) def test_delete(self): response = self.remotes_api.delete(self.remote.pulp_href) monitor_task(response.task) # verify the delete with self.assertRaises(ApiException): self.remotes_api.read(self.remote.pulp_href) def test_headers(self): # Test that headers value must be a list of dicts data = {"headers": {"Connection": "keep-alive"}} with self.assertRaises(ApiException): self.remotes_api.partial_update(self.remote.pulp_href, data) data = {"headers": [1, 2, 3]} with self.assertRaises(ApiException): self.remotes_api.partial_update(self.remote.pulp_href, data) data = {"headers": [{"Connection": "keep-alive"}]} self.remotes_api.partial_update(self.remote.pulp_href, data)
class CRUDRemoteTestCase(unittest.TestCase): """CRUD remotes.""" @classmethod def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() def setUp(self): self.client = FileApiClient(self.cfg.get_bindings_config()) self.remotes_api = RemotesFileApi(self.client) self.remote_attrs = { "name": utils.uuid4(), "url": FILE_FIXTURE_MANIFEST_URL, "ca_cert": None, "client_cert": None, "client_key": None, "tls_validation": False, "proxy_url": None, "username": "******", "password": "******", "download_concurrency": 10, "policy": "on_demand", "total_timeout": None, "connect_timeout": None, "sock_connect_timeout": None, "sock_read_timeout": None, } self.remote = self.remotes_api.create(self.remote_attrs) def _compare_results(self, data, received): for k in data: self.assertEqual(getattr(received, k), data[k]) def test_read(self): # Compare initial-attrs vs remote created in setUp self._compare_results(self.remote_attrs, self.remote) def test_update(self): data = {"download_concurrency": 66, "policy": "immediate"} self.remotes_api.partial_update(self.remote.pulp_href, data) time.sleep(1) # without this, the read returns the pre-patch values new_remote = self.remotes_api.read(self.remote.pulp_href) self._compare_results(data, new_remote) def test_timeout_attributes(self): # Test valid timeout settings (float >= 0) data = { "total_timeout": 1.0, "connect_timeout": 66.0, "sock_connect_timeout": 0.0, "sock_read_timeout": 3.1415926535, } self.remotes_api.partial_update(self.remote.pulp_href, data) time.sleep(1) new_remote = self.remotes_api.read(self.remote.pulp_href) self._compare_results(data, new_remote) def test_timeout_attributes_float_lt_zero(self): # Test invalid float < 0 data = { "total_timeout": -1.0, } with self.assertRaises(ApiException): self.remotes_api.partial_update(self.remote.pulp_href, data) def test_timeout_attributes_non_float(self): # Test invalid non-float data = { "connect_timeout": "abc", } with self.assertRaises(ApiException): self.remotes_api.partial_update(self.remote.pulp_href, data) def test_timeout_attributes_reset_to_empty(self): # Test reset to empty data = { "total_timeout": False, "connect_timeout": None, "sock_connect_timeout": False, "sock_read_timeout": None, } response = self.remotes_api.partial_update(self.remote.pulp_href, data) monitor_task(response.task) new_remote = self.remotes_api.read(self.remote.pulp_href) self._compare_results(data, new_remote) def test_delete(self): response = self.remotes_api.delete(self.remote.pulp_href) monitor_task(response.task) # verify the delete with self.assertRaises(ApiException): self.remotes_api.read(self.remote.pulp_href)