saltstack / saltstack/salt

[E2E Test] Add E2E test for fetching files from the file server

Open
#64,733 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Tests
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:

  1. 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.
  2. 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/
  1. 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
  1. Once that is all setup you should be able to run state.apply for 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

  1. Verify that the website contents have been updated for each environment properly
  2. 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.html with 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> 
  1. run salt \* state.apply web_update saltenv=dev -ldebug for only the dev environment and ensure the content is now there on the webserver. Ensure it is NOT on staging or prod.
  2. Now we want to update just one single file using salt's cp module for just the dev environment. Add this file: /srv/salt/dev/test.html with the contents: Testing feature.
  3. And run this command: salt \* cp.get_file salt://test.html /usr/share/nginx/html/dev/content/test.html saltenv=dev and ensure that file is now on dev website
  4. Even if we were to run state.apply with the other environments we should not see this file get updated on those servers since its only in dev's environment directory.
  5. Run salt-run fileserver.file_list saltenv=dev and you should see the test.html file.
  6. Run salt-run fileserver.file_list saltenv=staging and you should NOT see the test.html file.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.