def test_disable_and_delete_feed_group(self, api_conf): ensure_second_feed_enabled(api_conf) feed_list_resp = http_get(["system", "feeds"], config=api_conf) assert feed_list_resp == APIResponse(200) # Pick 2nd feed feeds = feed_list_resp.body feed = feeds[1] feed_name = feed.get("name") # Arbitrarily pick 1st group groups = feed.get("groups", []) group_to_delete = groups[0].get("name") resp = http_put( ["system", "feeds", feed_name, group_to_delete], None, {"enabled": False}, config=api_conf, ) assert resp == APIResponse(200) resp = http_del(["system", "feeds", feed_name, group_to_delete], config=api_conf) assert resp == APIResponse(200)
def test_update_policy_by_id(self, create_policy_from_artifact_and_teardown): """ Just gonna do a simple update (name change) here """ policy_bundle, policy_id, api_conf = create_policy_from_artifact_and_teardown resp = http_get(['policies', policy_id], config=api_conf) policy_json = resp.body[0] policy_json['name'] = 'UpdatedName' resp = http_put(['policies', policy_id], policy_json, config=api_conf) assert resp == APIResponse(200)
def disable_and_delete_functional_test_account(): """ This method wil dynamically, and in a blocking fashion, handle account deletion, which requires that the functional_test account be disabled before deletion. If the functional_test account is currently enabled, it will disable and then delete the account, waiting for the deletion to complete. If the functional_test account is already disabled, it will delete the account, and wait for the deletion to complete. If the functional_test account is currently awaiting deletion, it will wait for the deletion to complete. If the functional_test account is not found, it will exit. """ def await_account_deletion(): """ This method is helpful for awaiting account deletion of the functional_test account, with a timeout governed by DELETE_ACCOUNT_TIMEOUT_SEC. It awaits in 5 second intervals. """ start_time_sec = time.time() result = 200 while result != 404: time.sleep(5) ft_get_account_resp = http_get(['accounts', FT_ACCOUNT]) _logger.info("Waiting for functional_test account to fully delete. Time Elapsed={}sec" .format(int(time.time() - start_time_sec))) if not (ft_get_account_resp.code == 200 or ft_get_account_resp.code == 404): _logger.error(ft_get_account_resp) raise RequestFailedError(ft_get_account_resp.url, ft_get_account_resp.code, ft_get_account_resp.body) if time.time() - start_time_sec >= DELETE_ACCOUNT_TIMEOUT_SEC: raise TimeoutError('Timed out waiting for functional_test account to delete') result = ft_get_account_resp.code ft_account_resp = http_get(['accounts', FT_ACCOUNT]) if ft_account_resp.code == 404: _logger.info('functional_test account not found') return state = ft_account_resp.body.get('state') if state == 'enabled': _logger.info('functional_test account found, and enabled. Disabling') disable_account_resp = http_put(['accounts', FT_ACCOUNT, 'state'], {'state': 'disabled'}) if disable_account_resp.code != 200: raise RequestFailedError(disable_account_resp.url, disable_account_resp.code, disable_account_resp.body) elif state == 'deleting': _logger.info('functional_test account found, but is currently being deleted') await_account_deletion() return _logger.info('Deleting functional_test account') delete_resp = http_del(['accounts', FT_ACCOUNT]) if not (delete_resp.code == 200 or delete_resp.code == 404): raise RequestFailedError(delete_resp.url, delete_resp.code, delete_resp.body) await_account_deletion()
def ensure_second_feed_enabled(api_conf: callable): feed_list_resp = http_get(['system', 'feeds'], config=api_conf) if feed_list_resp.code != 200: raise RequestFailedError(feed_list_resp.url, feed_list_resp.code, feed_list_resp.body) resp = http_put(['system', 'feeds', feed_list_resp.body[0].get('name')], query={'enabled': True}, config=api_conf) if resp.code != 200: raise RequestFailedError(resp.url, resp.code, resp.body)
def test_update_subscription(self, add_alpine_subscription): subscription, api_conf = add_alpine_subscription resp = http_put( ["subscriptions", subscription.get("subscription_id")], { "active": False, "subscription_value": "docker.io/alpine:latest" }, config=api_conf, ) assert resp == APIResponse(200)
def ensure_second_feed_enabled(api_conf: callable): feed_list_resp = http_get(["system", "feeds"], config=api_conf) if feed_list_resp.code != 200: raise RequestFailedError(feed_list_resp.url, feed_list_resp.code, feed_list_resp.body) resp = http_put( ["system", "feeds", feed_list_resp.body[0].get("name")], query={"enabled": True}, config=api_conf, ) if resp.code != 200: raise RequestFailedError(resp.url, resp.code, resp.body)
def test_update_registry_by_name(self, add_and_teardown_registry): add_resp, api_conf = add_and_teardown_registry get_resp = http_get( ['registries', quote(get_registry_info()['service_name'], '')], config=api_conf) assert get_resp == APIResponse(200) # copy payload from existing (password isn't provided, so re-add it) update_payload = copy.copy(get_resp.body[0]) update_payload[ 'registry_name'] = 'updated_registry_name_functional_test' update_payload['registry_pass'] = get_registry_info()['pass'] update_resp = http_put(['registries', 'docker-registry:5000'], payload=update_payload, config=api_conf) assert update_resp == APIResponse(200)
def test_disable_and_delete_system_feeds(self, api_conf): """ Since this does kinda change some of the state around feeds be sure to not re-order without considering the other feed-related tests below """ feed_list_resp = http_get(['system', 'feeds'], config=api_conf) assert feed_list_resp == APIResponse(200) # Pick arbitrary first feed to disable & then delete feeds = feed_list_resp.body feed_to_delete = feeds[0].get('name') resp = http_put(['system', 'feeds', feed_to_delete], None, {'enabled': False}, config=api_conf) assert resp == APIResponse(200) resp = http_del(['system', 'feeds', feed_to_delete], config=api_conf) assert resp == APIResponse(200)
def test_update_registry_by_name(self, add_and_teardown_registry): add_resp, api_conf = add_and_teardown_registry get_resp = http_get( ["registries", quote(get_registry_info()["service_name"], "")], config=api_conf, ) assert get_resp == APIResponse(200) # copy payload from existing (password isn't provided, so re-add it) update_payload = copy.copy(get_resp.body[0]) update_payload[ "registry_name"] = "updated_registry_name_functional_test" update_payload["registry_pass"] = get_registry_info()["pass"] update_resp = http_put( ["registries", "docker-registry:5000"], payload=update_payload, config=api_conf, ) assert update_resp == APIResponse(200)
def test_disable_and_delete_feed_group(self, api_conf): ensure_second_feed_enabled(api_conf) feed_list_resp = http_get(['system', 'feeds'], config=api_conf) assert feed_list_resp == APIResponse(200) # Pick 2nd feed feeds = feed_list_resp.body feed = feeds[1] feed_name = feed.get('name') # Arbitrarily pick 1st group groups = feed.get('groups', []) group_to_delete = groups[0].get('name') resp = http_put(['system', 'feeds', feed_name, group_to_delete], None, {'enabled': False}, config=api_conf) assert resp == APIResponse(200) resp = http_del(['system', 'feeds', feed_name, group_to_delete], config=api_conf) assert resp == APIResponse(200)
def test_update_subscription(self, add_alpine_subscription): subscription, api_conf = add_alpine_subscription resp = http_put(['subscriptions', subscription.get('subscription_id')], {'active': False, 'subscription_value': 'docker.io/alpine:latest'}, config=api_conf) assert resp == APIResponse(200)