Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit 24d75c8

Browse files
committed
Consolidated secrets creation code, removed SecretHandler.
1 parent 6e31a5b commit 24d75c8

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

tests/test_spark.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def setup_module(module):
3232
utils.require_hdfs()
3333
utils.require_spark()
3434
utils.upload_file(os.environ["SCALA_TEST_JAR_PATH"])
35+
shakedown.run_dcos_command('package install --cli dcos-enterprise-cli --yes')
3536

3637

3738
def teardown_module(module):
@@ -299,11 +300,12 @@ def test_marathon_group():
299300

300301

301302
@pytest.mark.sanity
303+
@pytest.mark.secrets
302304
def test_secrets():
303305
properties_file_path = os.path.join(THIS_DIR, "resources", "secrets-opts.txt")
304-
secrets_handler = utils.SecretHandler(SECRET_NAME, SECRET_CONTENTS)
305-
r = secrets_handler.create_secret()
306-
assert r.ok, "Error creating secret, {}".format(r.content)
306+
# Create secret
307+
shakedown.run_dcos_command('security secrets create /{} --value {}'.format(SECRET_NAME, SECRET_CONTENTS))
308+
307309
secret_file_name = "secret_file"
308310
output = "Contents of file {}: {}".format(secret_file_name, SECRET_CONTENTS)
309311
args = ["--properties-file", properties_file_path,
@@ -313,9 +315,9 @@ def test_secrets():
313315
expected_output=output,
314316
app_name="/spark",
315317
args=args)
316-
r = secrets_handler.delete_secret()
317-
if not r.ok:
318-
LOGGER.warn("Error when deleting secret, {}".format(r.content))
318+
319+
# Delete secret
320+
shakedown.run_dcos_command('security secrets delete /{}'.format(SECRET_NAME))
319321

320322

321323
# Skip DC/OS < 1.10, because it doesn't have support for file-based secrets.
@@ -328,7 +330,6 @@ def test_driver_executor_tls():
328330
Put keystore and truststore as secrets in DC/OS secret store.
329331
Run SparkPi job with TLS enabled, referencing those secrets.
330332
'''
331-
shakedown.run_dcos_command('package install --cli dcos-enterprise-cli --yes')
332333
resources_folder = os.path.join(
333334
os.path.dirname(os.path.realpath(__file__)), 'resources'
334335
)
@@ -363,6 +364,8 @@ def test_driver_executor_tls():
363364
"--conf", "spark.mesos.executor.secret.filenames={},{}".format(keystore_file, truststore_file),
364365
"--conf", "spark.mesos.task.labels=DCOS_SPACE:/spark"
365366
])
367+
shakedown.run_dcos_command('security secrets delete /{}'.format(keystore_secret))
368+
shakedown.run_dcos_command('security secrets delete /{}'.format(truststore_secret))
366369

367370

368371
def _run_janitor(service_name):

tests/utils.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,6 @@ def check_job_output(task_id, expected_output):
170170
raise Exception("{} not found in stdout".format(expected_output))
171171

172172

173-
class SecretHandler():
174-
def __init__(self, path, value):
175-
self.payload = json.dumps({"value": value})
176-
self.api_url = urllib.parse.urljoin(dcos.config.get_config_val("core.dcos_url"),
177-
"secrets/v1/secret/default/{}".format(path))
178-
self.token = dcos.config.get_config_val("core.dcos_acs_token")
179-
self.headers = {"Content-Type": "application/json", "Authorization": "token={}".format(self.token)}
180-
181-
def create_secret(self):
182-
return requests.put(self.api_url, data=self.payload, headers=self.headers, verify=False)
183-
184-
def delete_secret(self):
185-
return requests.delete(self.api_url, headers=self.headers, verify=False)
186-
187-
188173
def upload_file(file_path):
189174
LOGGER.info("Uploading {} to s3://{}/{}".format(
190175
file_path,

0 commit comments

Comments
 (0)