Skip to content

Commit

Permalink
[pre-commit.ci] Apply automatic pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed May 8, 2024
1 parent ebdb6e4 commit 1073877
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions tests/tests_deployment/test_conda_store_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@
NEBARI_HOSTNAME = constants.NEBARI_HOSTNAME
# NEBARI_HOSTNAME = "pt.quansight.dev" ## Override for local testing

from contextlib import contextmanager
from base64 import b64encode
from contextlib import contextmanager


def b64encodestr(string):
return b64encode(string.encode("utf-8")).decode()


@contextmanager
def patched_secret_token(configuration):

try:
with kubernetes.client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = kubernetes.client.CoreV1Api(api_client)
name = 'conda-store-secret' # str | name of the Secret
namespace = 'dev' # str | object name and auth scope, such as for teams and projects
name = "conda-store-secret" # str | name of the Secret
namespace = "dev" # str | object name and auth scope, such as for teams and projects
elevated_token = str(uuid.uuid4())

try:
Expand All @@ -48,16 +50,27 @@ def patched_secret_token(configuration):
secret_config = json.loads(base64.b64decode(secret_data))

# Update secret
permissions = {'primary_namespace': '', 'role_bindings': {'*/*': ['admin']}}
permissions = {
"primary_namespace": "",
"role_bindings": {"*/*": ["admin"]},
}
secret_config["service-tokens"][elevated_token] = permissions
api_response.data = {"config.json": b64encodestr(json.dumps(secret_config))}
api_patch_response = api_instance.patch_namespaced_secret(name, namespace, api_response)
api_response.data = {
"config.json": b64encodestr(json.dumps(secret_config))
}
api_patch_response = api_instance.patch_namespaced_secret(
name, namespace, api_response
)

# Get pod name for conda-store
# Restart conda-store server pod
print(api_patch_response)
api_response = api_instance.list_namespaced_pod(namespace)
server_pod = [i for i in api_response.items if "nebari-conda-store-server-" in i.metadata.name][0]
server_pod = [
i
for i in api_response.items
if "nebari-conda-store-server-" in i.metadata.name
][0]
api_instance.delete_namespaced_pod(server_pod.metadata.name, namespace)
time.sleep(10)

Expand All @@ -71,25 +84,34 @@ def patched_secret_token(configuration):

# Update secret
secret_config["service-tokens"].pop(elevated_token)
api_response.data = {"config.json": b64encodestr(json.dumps(secret_config))}
api_patch_response = api_instance.patch_namespaced_secret(name, namespace, api_response)
api_response.data = {
"config.json": b64encodestr(json.dumps(secret_config))
}
api_patch_response = api_instance.patch_namespaced_secret(
name, namespace, api_response
)

# Get pod name for conda-store
# Restart conda-store server pod
print(api_patch_response)
api_response = api_instance.list_namespaced_pod(namespace)
server_pod = [i for i in api_response.items if "nebari-conda-store-server-" in i.metadata.name][0]
server_pod = [
i
for i in api_response.items
if "nebari-conda-store-server-" in i.metadata.name
][0]
api_instance.delete_namespaced_pod(server_pod.metadata.name, namespace)

except ApiException as e:
print("Exception when calling CoreV1Api->read_namespaced_secret: %s\n" % e)
print(
"Exception when calling CoreV1Api->read_namespaced_secret: %s\n" % e
)
finally:
# api_response_data["config.json"]["service-tokens"].pop(elevated_token)
# api_response = api_instance.patch_namespaced_secret(name, namespace, api_response_data)
pass



@pytest.mark.filterwarnings("ignore::urllib3.exceptions.InsecureRequestWarning")
@pytest.mark.filterwarnings("error")
class TestCondaStoreWorkerHPA(TestCase):
Expand Down Expand Up @@ -177,7 +199,9 @@ def test_scale_up_and_down(self):
self.build_n_environments(count)
self.log.info("Wait for 5 conda-store-worker pods to start.")
self.timed_wait_for_deployments(count)
self.log.info("Waiting (max 5 minutes) for all the conda environments to be created.")
self.log.info(
"Waiting (max 5 minutes) for all the conda environments to be created."
)
self.timed_wait_for_environment_creation(count)
self.log.info("Wait till worker deployment scales down to 0")
self.timed_wait_for_deployments(self.initial_deployment_count)
Expand Down

0 comments on commit 1073877

Please sign in to comment.