[E2E Test] Add E2E test for fetching files from the file server
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Add E2E test case for the following scenario:
- Ensure you have a webserver. The test suite has a webserver class that can be used in tests/support/helpers.py. For my manual example I'm just using nginx.
- Create a master config file with the following settings:
file_roots:
prod:
- /srv/salt/prod/
- /srv/salt/all/
staging:
- /srv/salt/staging/
- /srv/salt/all/
dev:
- /srv/salt/dev/
- /srv/salt/all/
- The contents of /srv/salt/all are the following:
/srv/salt/all/web_update.sls
{% import_yaml "site_data.yml" as site_data %}
website_index:
file.managed:
- name: {{ site_data.root_path }}/index.html
- source: salt://files/index.html
- template: jinja
- makedirs: True
- defaults:
saltenv: {{ saltenv }}
server_name: {{ site_data.server_name }}
port: {{ site_data.port }}
website_content:
file.recurse:
- name: {{ site_data.root_path }}/content/
- source: salt://files/content/
- makedirs: True
/srv/salt/all/files/index.html
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to {{ server_name }}</h1>
<p>This server is running on port {{ port }}.</p>
<p> This is the {{ saltenv }} environment. </p>
<p> Find out more about us <a href="http://{{ server_name }}/content/about.html">here</a>
</body>
</html>
/srv/salt/all/files/content/about.html
We are a team creating an awesome website.
And here are the contents for each environments directory:
/srv/salt/dev/site_data.yml
server_name: dev.website.com
root_path: /usr/share/nginx/html/dev/
port: 8000
/srv/salt/staging/site_data.yml
server_name: staging.website.com
root_path: /usr/share/nginx/html/staging/
port: 8001
/srv/salt/prod/site_data.yml
server_name: website.com
root_path: /usr/share/nginx/html/prod/
port: 80
- Once that is all setup you should be able to run
state.applyfor each environment to update it:
salt \* state.apply web_update saltenv=dev -ldebug
salt \* state.apply web_update saltenv=staging -ldebug
salt \* state.apply web_update saltenv=prod -ldebug
- Verify that the website contents have been updated for each environment properly
- Now the team wants to update the website with a contact us page. They want to ensure this is updated to dev first, and then the other environments when its confirmed to look good. So create this file:
/srv/salt/all/files/content/contactus.htmlwith the content:
<!DOCTYPE html>
<html>
<body>
<h1>Contact information</h1>
<p>If you have any questions contact us at webserver-team@email.com</p>
</body>
</html>
- run
salt \* state.apply web_update saltenv=dev -ldebugfor only the dev environment and ensure the content is now there on the webserver. Ensure it is NOT on staging or prod. - Now we want to update just one single file using salt's
cpmodule for just the dev environment. Add this file:/srv/salt/dev/test.htmlwith the contents:Testing feature. - And run this command:
salt \* cp.get_file salt://test.html /usr/share/nginx/html/dev/content/test.html saltenv=devand ensure that file is now on dev website - Even if we were to run
state.applywith the other environments we should not see this file get updated on those servers since its only in dev's environment directory. - Run
salt-run fileserver.file_list saltenv=devand you should see thetest.htmlfile. - Run
salt-run fileserver.file_list saltenv=stagingand you should NOT see the test.html file.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the E2E test structure and tests/support/helpers.py, especially the reusable webserver class, then review how existing tests invoke state.apply, cp.get_file, and fileserver.file_list. Done means the test covers environment-specific state and file fetching, verifies contactus.html and test.html only appear in dev, and confirms file_list differs between dev and staging.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nginx, python
- Domain
- infrastructure, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100