diff --git a/frameworks/helloworld/tests/conftest.py b/frameworks/helloworld/tests/conftest.py index 5e249b96c9d..a05c7906d97 100644 --- a/frameworks/helloworld/tests/conftest.py +++ b/frameworks/helloworld/tests/conftest.py @@ -14,6 +14,8 @@ def pytest_addoption(parser): help='Number of hello world services to deploy with a given scenario') parser.addoption("--scenario", action='store', default='', help="hello world service yml to use") + parser.addoption("--service-name", action='store', default='hello-world', + help="custom service name to be used instead of default 'hello-world'") @pytest.fixture @@ -24,3 +26,8 @@ def service_count(request) -> int: @pytest.fixture def scenario(request) -> str: return str(request.config.getoption('--scenario')) + + +@pytest.fixture +def service_name(request) -> str: + return str(request.config.getoption('--service-name')) diff --git a/frameworks/helloworld/tests/scale/test_scale.py b/frameworks/helloworld/tests/scale/test_scale.py index daa246a5c57..75cca845288 100644 --- a/frameworks/helloworld/tests/scale/test_scale.py +++ b/frameworks/helloworld/tests/scale/test_scale.py @@ -8,21 +8,46 @@ log = logging.getLogger(__name__) +@pytest.mark.soak +def test_soak_load(service_name, + scenario) -> None: + """Launch a soak test scenario. This does not verify the results + of the test, but does ensure the instances were created. + + Args: + service_name: name of the service to install as + scenario: yaml scenario to run helloworld with (normal, crashloop) are added for this case + """ + # Note service-names *cannot* have underscores in them. + soak_service_name = ("{}-{}-soak".format(service_name, scenario)).replace("_", "-") + # service-names can have '/'s in them but service account names cannot, sanitize here. + service_account_name = soak_service_name.replace("/", "__") + security_info = _create_service_account(service_account_name) + _install_service(soak_service_name, + scenario, + security_info) + + @pytest.mark.scale -def test_scaling_load(service_count, +def test_scaling_load(service_name, + service_count, scenario) -> None: """Launch a load test scenario. This does not verify the results of the test, but does ensure the instances were created. Args: + service_name: name of the service to install as service_count: number of helloworld services to install scenario: yaml scenario to run helloworld with (normal, crashloop) are added for this case """ # TODO: parallelize account creation and installation if time is an issue in scale tests for index in range(service_count): - service_name = "{}-{}-{}".format(config.PACKAGE_NAME, scenario, index) - security_info = _create_service_account(service_name) - _install_service(service_name, + # Note service-names *cannot* have underscores in them. + scale_service_name = ("{}-{}-{}".format(service_name, scenario, index)).replace("_", "-") + # service-names can have '/'s in them but service account names cannot, sanitize here. + service_account_name = scale_service_name.replace("/", "__") + security_info = _create_service_account(service_account_name) + _install_service(scale_service_name, scenario, security_info) diff --git a/testing/sdk_utils.py b/testing/sdk_utils.py index 403bb53ad01..496493437c7 100644 --- a/testing/sdk_utils.py +++ b/testing/sdk_utils.py @@ -16,6 +16,7 @@ import sdk_cmd from distutils.version import LooseVersion +from enum import Enum log = logging.getLogger(__name__) @@ -24,6 +25,11 @@ # Service/task names ### +class DCOS_SECURITY(Enum): + disabled = 1 + permissive = 2 + strict = 3 + def get_package_name(default: str) -> str: return os.environ.get("INTEGRATION_TEST__PACKAGE_NAME") or default @@ -111,7 +117,7 @@ def your_test_here(): ... In order for this annotation to take effect, this function must be called by a pytest_runtest_setup() hook. """ - min_version_mark = item.get_marker("dcos_min_version") + min_version_mark = item.get_closest_marker("dcos_min_version") if min_version_mark: min_version = min_version_mark.args[0] message = "Feature only supported in DC/OS {} and up".format(min_version) @@ -129,7 +135,19 @@ def is_open_dcos(): def is_strict_mode(): """Determine if the tests are being run on a strict mode cluster.""" - return os.environ.get("SECURITY", "") == "strict" + return get_security_mode() == DCOS_SECURITY.strict + + +def get_security_mode() -> DCOS_SECURITY: + r = get_metadata().json() + mode = r['security'] + return DCOS_SECURITY[mode] + + +def get_metadata(): + return sdk_cmd.cluster_request('GET', + 'dcos-metadata/bootstrap-config.json', + retry=False) """Annotation which may be used to mark test suites or test cases as EE-only.