Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Anaconda WebUI plugin to reflect changes made in anaconda repo #78

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions doc/workflows/anaconda-webui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ Examples can be found in `default settings file <https://github.com/rhinstaller/

AnacondaWebUI
^^^^^^^^^^^^^
- **anaconda_repo** - URL to Anaconda git repository or path to local directory (use file://)
- **cockpit_repo** - URL to Cockpit git repository, if anaconda_repo is local directory and
``anaconda/ui/webui/test/common`` exists, this repo won't be used.
- **webui_repo** - URL to anaconda-webui git repository or path to local directory (use file://)
- **cockpit_repo** - URL to Cockpit git repository, if webui_repo is local directory and
``./test/common`` exists, this repo won't be used.
- **cockpit_branch** - Cockpit git branch
- **bots_repo** - URL to Cockpit Bots git repository, if anaconda_repo is local directory and
``anaconda/ui/webui/bots`` exists, this repo won't be used.
- **bots_repo** - URL to Cockpit Bots git repository, if webui_repo is local directory and
``./bots`` exists, this repo won't be used.
- **bots_branch** - Cockpit Bots git branch
- **hypervisor_vm_limit** - How many VMs can this workflow use at once
- **use_container** - Run npm command and the test itself inside podman container.
Expand Down Expand Up @@ -90,8 +90,8 @@ are:

- **script_file** - path to the test script, by default the base for this path
is anaconda git repository
- **test_case** - python class in the script file (test script file can contain
multiple test cases)
- **test_case** - python class and method in the script file (test script file
can contain multiple test cases)

Optional automation_data:

Expand All @@ -107,16 +107,16 @@ Example of minimal execution section for running test from anaconda repo::
execution:
type: anaconda-webui
automation_data:
script_file: ./ui/webui/test/end2end/default.py
test_case: DefaultInstallation
script_file: ./test/check-progress
test_case: TestInstallationProgress.testBasic

Example of execution section with all options set::

execution:
type: anaconda-webui
automation_data:
script_file: ./check-navigation.py
test_case: TestNavigation
test_case: TestNavigation.testInstall
test_repo: my-special-tests
additional_repos: ['AppStream', 'CRB']
kernel_cmdline: 'nosmt'
Expand Down Expand Up @@ -164,7 +164,7 @@ We have special command that make this the easiest way to run WebUI test.
4. (optional) create new test case and test script file in the anaconda repository
we just cloned.

1. Create new file `anaconda/ui/webui/test/end2end/my_new_test.tc.yaml` with
1. Create new file `anaconda-webui/test/test_cases/my_new_test.tc.yaml` with
following content::

name: My new test
Expand All @@ -176,33 +176,31 @@ We have special command that make this the easiest way to run WebUI test.
execution:
type: anaconda-webui
automation_data:
script_file: ./ui/webui/test/end2end/my_new_test.py
test_case: MyNewTest
script_file: ./test/my_new_test.py
test_case: MyNewTest.testMethod
instructions:
steps:
- step: Describe your test steps here

2. Copy any existing test script to `anaconda/ui/webui/test/end2end/my_new_test.py`,
good examples are listed in `Integration tests examples <https://anaconda-installer.readthedocs.io/en/latest/testing.html#end-to-end-tests-examples>`.
3. Change test class name in the test script to `MyNewTest`
2. Create your test script in `anaconda-webui/test/my_new_test.py`

5. Run the new test case::

PYTHONPATH=../tplib ./pipeline run_awebui_tc ../anaconda 'My new test'
PYTHONPATH=../tplib ./pipeline run_awebui_tc ../anaconda-webui 'My new test'

.. note::
This command makes sure your local anaconda repository is used as the source of the
test script. Usually Permian clones its own copy of the anaconda repository.
This command makes sure your local anaconda-webui repository is used as the source of the
test script. Usually Permian clones its own copy of the anaconda-webui repository.

Run test plan from Anaconda repo
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Run test plan from Anaconda-webui repo
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1. Follow the guide on page :ref:`Quick start<Quick start>` and get Permian
running without an container.
2. By default your system will be used as :ref:`hypervisor`, so make sure libvirtd is running.
3. Clone Anaconda repository, we are going to use the testplan library from it::
3. Clone Anaconda-webui repository, we are going to use the testplan library from it::

git clone https://github.com/rhinstaller/anaconda.git
git clone https://github.com/rhinstaller/anaconda-webui.git

.. note::
In this case the test scripts are going to be sourced separetly by the workflow.
Expand All @@ -216,7 +214,7 @@ Run test plan from Anaconda repo
is InstallationSource event structure.::

PYTHONPATH=../tplib ./pipeline run_event \
-o "library.directPath=../anaconda/ui/webui/test/end2end/" \
-o "library.directPath=../anaconda-webui/test/test_cases/" \
'{"type": "github.scheduled.preview",
"InstallationSource": {
"base_repo_id": "bootiso",
Expand Down
42 changes: 21 additions & 21 deletions libpermian/plugins/anaconda_webui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def __init__(self, testRuns, crcList, setup_lock, vm_semaphore):
self.debug = self.settings.getboolean('AnacondaWebUI', 'debug')
self.test_timeout = self.settings.getint('AnacondaWebUI', 'test_timeout')

self.git_anaconda_repo = self.settings.get('AnacondaWebUI', 'anaconda_repo')
self.git_anaconda_branch = self.crc.configuration['branch']
self.git_webui_repo = self.settings.get('AnacondaWebUI', 'webui_repo')
self.git_webui_branch = self.crc.configuration['branch']
self.git_cockpit_repo = self.settings.get('AnacondaWebUI', 'cockpit_repo')
self.git_cockpit_branch = self.settings.get('AnacondaWebUI', 'cockpit_branch')
self.git_bots_repo = self.settings.get('AnacondaWebUI', 'bots_repo')
Expand Down Expand Up @@ -213,20 +213,19 @@ def setup(self):
self.container = ExecutionContainer(container_build_log)

# Add self to instances using this branch setup
if self.git_anaconda_branch in self.instances:
self.instances[self.git_anaconda_branch].append(self)
if self.git_webui_branch in self.instances:
self.instances[self.git_webui_branch].append(self)
else:
self.instances[self.git_anaconda_branch] = [self]
self.instances[self.git_webui_branch] = [self]

# Create temporary directory for this branch setup - if it doesn't exists
if self.git_anaconda_branch not in self.temp_dirs.keys():
self.temp_dirs[self.git_anaconda_branch] = tempfile.TemporaryDirectory(dir='/var/tmp/', prefix="pipeline_awebui_")
if self.git_webui_branch not in self.temp_dirs.keys():
self.temp_dirs[self.git_webui_branch] = tempfile.TemporaryDirectory(dir='/var/tmp/', prefix="pipeline_awebui_")
clone_common = True

self.temp_dir = self.temp_dirs[self.git_anaconda_branch].name
self.temp_dir = self.temp_dirs[self.git_webui_branch].name
os.chmod(self.temp_dir, 755)
self.anaconda_dir = os.path.join(self.temp_dir, 'anaconda')
self.webui_dir = os.path.join(self.anaconda_dir, 'ui/webui')
self.webui_dir = os.path.join(self.temp_dir, 'anaconda-webui')

if self.test_repo_name:
self._clone_test_repo()
Expand All @@ -240,7 +239,7 @@ def setup(self):
if self.installation_source is None:
self._set_boot_iso_path()

self.test_workdir = self.anaconda_dir # CWD where the test is going to run
self.test_workdir = self.webui_dir # CWD where the test is going to run
if self.test_repo_name:
self.test_workdir = self.test_repo_dir

Expand Down Expand Up @@ -305,6 +304,7 @@ def execute(self):

test_env = {'WEBUI_TEST_DIR': os.path.abspath(os.path.join(self.webui_dir, 'test'))}
test_env['TEST_AUDIT_NO_SELINUX'] = '1'
test_env['EXTENDED_LOGGING'] = '1'
test_output = self.crc.openLogfile('output.txt', 'w', True)

time.sleep(10) # Workaround, there is a race-condition, where WebUI is accessible but /run/anaconda/bus.address doesn't exist yet
Expand Down Expand Up @@ -387,11 +387,11 @@ def teardown(self):

with self.setup_lock:
# If this instance is the last one using temp dir -> remove it
self.instances[self.git_anaconda_branch].remove(self)
if len(self.instances[self.git_anaconda_branch]) == 0:
self.temp_dirs[self.git_anaconda_branch].cleanup()
self.instances[self.git_webui_branch].remove(self)
if len(self.instances[self.git_webui_branch]) == 0:
self.temp_dirs[self.git_webui_branch].cleanup()

del self.instances[self.git_anaconda_branch]
del self.instances[self.git_webui_branch]
# Remove container image, if this was the last anacoda-webui workflow
if not self.instances:
self.container.remove_image()
Expand Down Expand Up @@ -579,21 +579,21 @@ def _clone_test_repo(self):
self.test_repo_dir = os.path.join(self.temp_dir, self.test_repo_name)
if not os.path.isdir(self.test_repo_dir):
self.log(f'Clonning test repo {self.test_repo_url}')
self._clone_repo(self.test_repo_url, self.git_anaconda_branch, self.test_repo_dir)
self._clone_repo(self.test_repo_url, self.git_webui_branch, self.test_repo_dir)

def _clone_common(self):
""" Clones repositories common to all Anaconda WebUI tests """
self.log(f'Clonning common repositories')
bots_dir = os.path.join(self.webui_dir, 'bots')
cockpit_common_dir = os.path.join(self.anaconda_dir, 'ui/webui/test/common')
parsed_anaconda_url = urllib.parse.urlparse(self.git_anaconda_repo)
cockpit_common_dir = os.path.join(self.webui_dir, 'test/common')
parsed_webui_url = urllib.parse.urlparse(self.git_webui_repo)

if parsed_anaconda_url.scheme == 'file':
if parsed_webui_url.scheme == 'file':
# Create copy of anaconda repo
shutil.copytree(parsed_anaconda_url.path, self.anaconda_dir, symlinks=True, ignore_dangling_symlinks=True)
shutil.copytree(parsed_webui_url.path, self.webui_dir, symlinks=True, ignore_dangling_symlinks=True)
else:
# clone anaconda
self._clone_repo(self.git_anaconda_repo, self.git_anaconda_branch, self.anaconda_dir)
self._clone_repo(self.git_webui_repo, self.git_webui_branch, self.webui_dir)

if not os.path.exists(cockpit_common_dir):
with tempfile.TemporaryDirectory() as temp_dir:
Expand Down
12 changes: 6 additions & 6 deletions libpermian/plugins/anaconda_webui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
@api.cli.register_command_parser('run_awebui_tc')
def run_awebui_tc_command(base_parser, args):
parser = base_parser
parser.add_argument('path_to_anaconda',
help='Path to local Anaconda git repository where the test case is located')
parser.add_argument('path_to_webui',
help='Path to local Anaconda-webui git repository where the test case is located')
parser.add_argument('test_case_name',
help='Name of the test case as specified in tc.yaml')
source_group = parser.add_mutually_exclusive_group()
source_group.add_argument('--install-source',
default='https://fedorapeople.org/groups/anaconda/webui_permian_tests/sources/periodic/x86_64/',
help='URL of the installation source (compose os directory or unpack iso')
help='URL of the installation source (compose os directory or iso')
source_group.add_argument('--compose',
help='Compose ID of a compose that should be used as installation source')
parser.add_argument('--compose-url',
Expand Down Expand Up @@ -64,11 +64,11 @@ def run_awebui_tc_command(base_parser, args):

os.environ.setdefault(
"PIPELINE_library_directPath",
os.path.join(options.path_to_anaconda, 'ui/webui/test/end2end/'),
os.path.join(options.path_to_webui, 'test/test_cases/'),
)
os.environ.setdefault(
"PIPELINE_AnacondaWebUI_anaconda_repo",
'file://' + os.path.abspath(options.path_to_anaconda),
"PIPELINE_AnacondaWebUI_webui_repo",
'file://' + os.path.abspath(options.path_to_webui),
)

return options, json.dumps(event)
2 changes: 1 addition & 1 deletion libpermian/plugins/anaconda_webui/settings.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[AnacondaWebUI]
# Anaconda repo, use file:// to copy local directory or anything else to clone git repo
anaconda_repo=https://github.com/rhinstaller/anaconda.git
webui_repo=https://github.com/rhinstaller/anaconda-webui.git
cockpit_repo=https://github.com/cockpit-project/cockpit.git
cockpit_branch=289
bots_repo=https://github.com/cockpit-project/bots.git
Expand Down
2 changes: 1 addition & 1 deletion libpermian/plugins/anaconda_webui/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_execute(self, mocked_run, mocked_sleep, list_dir, mocked_openLogfile):
mocked_run.assert_called_with(['podman', 'run', '--rm', '-it', '-v',
'/test/temp:/root/workdir:z', '-w', '/root/workdir/workdir',
'-e', 'WEBUI_TEST_DIR=/root/workdir/workdir/webui/test', '-e', 'TEST_AUDIT_NO_SELINUX=1',
'anaconda-webui', 'file', 'Case', '--browser', '192.168.122.42:8000',
'-e', 'EXTENDED_LOGGING=1', 'anaconda-webui', 'file', 'Case', '--browser', '192.168.122.42:8000',
'--machine', '192.168.122.42:11'], stderr=-2, stdout=ANY)

self.workflow.reportResult.assert_called_with(Result('complete', 'PASS', True))
Expand Down