Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Add quota to testing (#217)
Browse files Browse the repository at this point in the history
* Add quota to testing

* Fix quota setup
  • Loading branch information
benclarkwood authored May 2, 2018
1 parent bb2cb8a commit 79dd437
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
7 changes: 7 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def pytest_addoption(parser):
help='Use Mesos Single-Use agents')
parser.addoption('--run-delay', action='store', default=1,
help='Run job every X minutes.')
parser.addoption('--cpu-quota', action='store', default=0.0,
help='CPU quota to set. 0.0 to set no quota.')


@pytest.fixture
Expand All @@ -46,3 +48,8 @@ def single_use(request) -> int:
@pytest.fixture
def run_delay(request) -> int:
return int(request.config.getoption('--run-delay'))


@pytest.fixture
def cpu_quota(request) -> float:
return float(request.config.getoption('--cpu-quota'))
22 changes: 15 additions & 7 deletions testing/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@
log = logging.getLogger(__name__)


def install(service_name):
def install(service_name, role=None):
"""Install a Jenkins instance and set the service name to
`service_name`. This does not wait for deployment to finish.
Args:
service_name: Unique service name
role: The role for the service to use (default is no role)
"""
options = {
"service": {
"name": service_name
}
}

if role:
options["roles"] = {
"jenkins-agent-role": role
}

sdk_install.install(
'jenkins',
service_name,
0,
additional_options={
"service": {
"name": service_name
}
},
additional_options=options,
wait_for_deployment=False)


Expand Down Expand Up @@ -59,7 +67,7 @@ def create_job(
svc_url = dcos_service_url(service_name)
url = "{}createItem?name={}".format(svc_url, job_name)
job_config = construct_job_config(cmd, schedule_frequency_in_min, labelString)

r = http.post(url, headers=headers, data=job_config)

return r
Expand Down
41 changes: 36 additions & 5 deletions tests/scale/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
From the CLI, this can be run as follows:
$ PYTEST_ARGS="--masters=3 --jobs=10" ./test.sh -m scale jenkins
To specify a CPU quota (what JPMC does) then run:
$ PYTEST_ARGS="--masters=3 --jobs=10 --cpu-quota=10.0" ./test.sh -m scale jenkins
And to clean-up a test run of Jenkins instances:
$ ./test.sh -m scalecleanup jenkins
Expand All @@ -27,15 +29,20 @@
import sdk_install
import sdk_marathon
import sdk_utils
import sdk_quota

log = logging.getLogger(__name__)


SHARED_ROLE = "jenkins-role"


@pytest.mark.scale
def test_scaling_load(master_count,
job_count,
single_use,
run_delay):
run_delay,
cpu_quota):
"""Launch a load test scenario. This does not verify the results
of the test, but does ensure the instances and jobs were created.
Expand All @@ -49,6 +56,9 @@ def test_scaling_load(master_count,
single_use: Mesos Single-Use Agent on (true) or off (false)
run_delay: Jobs should run every X minute(s)
"""
if cpu_quota is not 0.0:
_setup_quota(SHARED_ROLE, cpu_quota)

masters = ["jenkins{}".format(sdk_utils.random_string()) for _ in
range(0, int(master_count))]
# launch Jenkins services
Expand All @@ -63,7 +73,7 @@ def test_scaling_load(master_count,
thread.join()
# now try to launch jobs
for service_name in masters:
m_label = _create_random_label(service_name)
m_label = _create_executor_configuration(service_name)
_launch_jobs(service_name, job_count, single_use, run_delay, m_label)


Expand Down Expand Up @@ -95,14 +105,35 @@ def test_cleanup_scale():
thread.join()


def _setup_quota(role, cpus):
current_quotas = sdk_quota.list_quotas()
if "infos" not in current_quotas:
_set_quota(role, cpus)
return

match = False
for quota in current_quotas["infos"]:
if quota["role"] == role:
match = True
break

if match:
sdk_quota.remove_quota(role)
_set_quota(role, cpus)


def _set_quota(role, cpus):
sdk_quota.create_quota(role, cpus=cpus)


def _install_jenkins(service_name):
"""Install Jenkins service.
Args:
service_name: Service Name or Marathon ID (same thing)
"""
log.info("Installing jenkins '{}'".format(service_name))
jenkins.install(service_name)
jenkins.install(service_name, role=SHARED_ROLE)


def _cleanup_jenkins_install(service_name):
Expand All @@ -119,7 +150,7 @@ def _cleanup_jenkins_install(service_name):
sdk_install.uninstall(config.PACKAGE_NAME, service_name)


def _create_random_label(service_name):
def _create_executor_configuration(service_name):
"""Create a new Mesos Slave Info configuration with a random name.
Args:
Expand All @@ -128,7 +159,7 @@ def _create_random_label(service_name):
Returns: Random name of the new config created.
"""
mesos_label = "mesos{}".format(sdk_utils.random_string())
mesos_label = "mesos"
jenkins.create_mesos_slave_node(mesos_label,
service_name=service_name,
executorCpus=0.1,
Expand Down

0 comments on commit 79dd437

Please sign in to comment.