Skip to content

Commit

Permalink
Add '-i' option to specify which configurations should be executed
Browse files Browse the repository at this point in the history
  • Loading branch information
fchauvel committed Oct 30, 2019
1 parent 0fd283a commit dca60bd
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 15 deletions.
21 changes: 18 additions & 3 deletions camp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def extract_from(command_line):
"--directory",
dest="working_directory",
help="the directory that contains the input files")
execute.add_argument(
"-i",
"--include",
dest="included",
nargs='+',
type=int,
help="Set the indexes of the configurations to execute")
execute.add_argument(
"-s",
"--simulated",
Expand All @@ -98,7 +105,8 @@ def from_namespace(namespace):

elif namespace.command == "execute":
return Execute(namespace.working_directory,
namespace.is_simulated)
namespace.is_simulated,
namespace.included)

elif namespace.command == "show_version":
return ShowVersions()
Expand Down Expand Up @@ -178,19 +186,26 @@ class Execute(Command):
"""

DEFAULT_IS_SIMULATED = False

DEFAULT_INCLUDED = []

def __init__(self,
working_directory=None,
is_simulated=None):
is_simulated=None,
included=None):
super(Execute, self).__init__(working_directory)
self._is_simulated = is_simulated or self.DEFAULT_IS_SIMULATED
self._included = included or self.DEFAULT_INCLUDED

@property
def is_simulated(self):
return self._is_simulated


@property
def included_configurations(self):
return self._included


def send_to(self, camp):
camp.execute(self)

Expand Down
25 changes: 24 additions & 1 deletion camp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ def execute(self, arguments):
model = self._load_model()
testing = model.tests
configurations = self._load_configurations(model)
selected_configurations = self._filter(arguments, list(configurations))
with open("camp_execute.log", "wb") as log_file:
shell = self._select_shell(arguments, log_file)
engine = Engine(testing, shell, self._ui)
reports = engine.execute(configurations)
reports = engine.execute(selected_configurations)
self._output.save_reports(reports)
self._ui.summarize_execution(reports)

Expand Down Expand Up @@ -205,3 +206,25 @@ def _select_shell(self, arguments, log_file):
if arguments.is_simulated:
shell = SimulatedShell(log_file, ".", self._ui)
return shell


def _filter(self, arguments, configurations):
if len(arguments._included) == 0:
return configurations

selection = []
for each_index in arguments._included:
found = self._search_for(each_index, configurations)
if not found:
self._ui.no_configuration_with_index(each_index)
else:
selection.append(found)
return selection


def _search_for(self, index, configurations):
marker = "config_{}".format(index)
for any_path, any_config in configurations:
if marker in any_path:
return (any_path, any_config)
return None
4 changes: 4 additions & 0 deletions camp/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def no_configuration_found(self, error):
self._print(" Have you run 'camp generate -d {folder}?",
folder=error.searched_folder)

def no_configuration_with_index(self, index):
self._print("Warning: No configuration found with index {index}",
index=index)


def invalid_substitution(self, error):
self._print(self.INVALID_SUBSTITUTION, searched=error.pattern,
Expand Down
22 changes: 14 additions & 8 deletions docs/pages/execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ the test reports.

Here is the usage and options:
```console
$ camp execute --help
usage: CAMP execute [-h] [-d WORKING_DIRECTORY] [-s]
$ camp execute -h
usage: CAMP execute [-h] [-d WORKING_DIRECTORY] [-i INCLUDED [INCLUDED ...]] [-s]

optional arguments:
-h, --help show this help message and exit
-d WORKING_DIRECTORY, --directory WORKING_DIRECTORY
the directory that contains the input files
-i INCLUDED [INCLUDED ...], --include INCLUDED [INCLUDED ...]
Set the indexes of the configurations to execute
-s, --simulated Display but do NOT execute the commands that CAMP triggers
```

Expand Down Expand Up @@ -183,15 +185,17 @@ public void testStatusCode() throws Exception {

### Running CAMP Execute

To run camp execute, you must already have generated and realized the
To run camp execute, you must already have generated and realised the
configuration. On this Java example, CAMP generates three
configurations, one per version of Tomcat.
configurations, one per version of Tomcat. Note the `--include` option
(from v0.7) that lets you specify the indexes of the configurations you
want to execute. By default, CAMP executes all configurations.

```console
$ camp generate -d .
$ camp realize -d .
$ camp execute -d .
CAMP v0.3.3 (MIT)
$ camp execute -d .
CAMP v0.7.0 (MIT)
Copyright (C) 2017 -- 2019 SINTEF Digital

Loaded './camp.yaml'.
Expand Down Expand Up @@ -251,6 +255,8 @@ TOTAL 3 3 0 0

That's all folks
```


## Example: Performance Test A Java WebApp

In this example you will see how to use CAMP to generate new configurations, to be performance tested with [Apache JMeter](https://jmeter.apache.org/).
Expand Down Expand Up @@ -366,7 +372,7 @@ More specifically, the `tests` Dockerfile leverages a JMeter docker image availa
#### The Testman webapp
Our web test managemeent tool is a Spring Roo web application. Here the Java
Our web test management tool is a Spring Roo web application. Here the Java
code of the Java web application, but we also have the necessary
[`web.xml`](http://github.com/stamp-project/camp/tree/master/samples/java-web/template/testman/src/main/webapp/WEB-INF/web.xml)
to specify servlets' bindings and the [Maven POM
Expand Down Expand Up @@ -491,4 +497,4 @@ java-web
:
.
```
Moreover, .jtl files are available to be used, for instance, with Jenkins JMeter plugin (which looks for .jtl reports).
Moreover, .jtl files are available to be used, for instance, with Jenkins JMeter plugin (which looks for .jtl reports).
10 changes: 10 additions & 0 deletions tests/acceptance/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ def test_run_all_tests_three_times(self):
report = self.scenario.fetch_test_report()

self.assertEqual(3, len(report["reports"]))


def test_run_only_configuration_number_two(self):
self.generate_all()
self.realize()
self.execute(simulated=True, include=[2])

report = self.scenario.fetch_test_report()

self.assertEqual(1, len(report["reports"]))
31 changes: 31 additions & 0 deletions tests/commands/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def test_with_the_simulation_option(self):
self.assertEqual(True,
command.is_simulated)

def test_with_the_include_option(self):
command_line = ["execute", "--include", "1", "2", "3", "4"]

command = Command.extract_from(command_line)

self.assertIsInstance(command, Execute)
self.assertEqual([1, 2, 3, 4],
command.included_configurations)



class ShortOptionsAreAccepted(TestCase):

Expand All @@ -61,6 +71,17 @@ def test_with_the_simulation_option(self):
command.is_simulated)


def test_with_the_include_option(self):
command_line = ["execute", "-i", "1", "2", "3", "4"]

command = Command.extract_from(command_line)

self.assertIsInstance(command, Execute)
self.assertEqual([1, 2, 3, 4],
command.included_configurations)



class DefaultValuesAreCorrect(TestCase):

def setUp(self):
Expand Down Expand Up @@ -89,3 +110,13 @@ def test_when_no_argument_is_given(self):
self.assertIsInstance(command, Execute)
self.assertEqual(Execute.DEFAULT_IS_SIMULATED,
command.is_simulated)


def test_with_the_include_option(self):
command_line = ["execute"]

command = Command.extract_from(command_line)

self.assertIsInstance(command, Execute)
self.assertEqual(Execute.DEFAULT_INCLUDED,
command.included_configurations)
12 changes: 9 additions & 3 deletions tests/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ def realize(self):
self.camp("realize", "-d", self.scenario.directory)


def execute(self):
self.camp("execute",
"-d", self.scenario.directory)
def execute(self, simulated=False, include=None):
parameters = ["execute", "-d", self.scenario.directory]
if simulated:
parameters.append("-s")
if include:
parameters.append("--include")
for each in include:
parameters.append(str(each))
self.camp(*parameters)

@staticmethod
def camp(*arguments):
Expand Down

0 comments on commit dca60bd

Please sign in to comment.