Browse Source

Merge branch 'fix_yamlloadwarnings' into 'master'

Fix YAMLLoadWarning: use 'yaml.safe_load'

See merge request main/infrastructure!365
keep-around/71c7f3658e93bd5ab3b2577579aa720cd86203db
Loïc Dachary 10 months ago
parent
commit
71c7f3658e
  1. 2
      enough/common/__init__.py
  2. 4
      enough/common/dotenough.py
  3. 2
      enough/common/openstack.py
  4. 2
      playbooks/api/tests/test_api.py
  5. 2
      playbooks/gitlab/tests/gitlab_utils.py
  6. 2
      playbooks/icinga/tests/test_icinga_checks.py
  7. 2
      playbooks/icinga/tests/test_icingaweb.py
  8. 2
      playbooks/icinga/tests/test_letsencrypt.py
  9. 2
      playbooks/openedx/tests/test_openedx.py
  10. 2
      playbooks/psono/tests/test_psono.py
  11. 2
      playbooks/wazuh/tests/test_wazuh.py
  12. 2
      playbooks/weblate/tests/test_weblate.py
  13. 2
      playbooks/wordpress/tests/test_wordpress.py
  14. 4
      tests/enough/common/test_ansible_utils.py
  15. 6
      tests/enough/common/test_dotenough.py
  16. 2
      tests/enough/common/test_init.py
  17. 2
      tests/icinga_helper.py
  18. 2
      tests/infrastructure.py

2
enough/common/__init__.py

@ -92,7 +92,7 @@ class Enough(object):
@staticmethod
def replace_production(clouds, target_cloud):
content = yaml.load(open(clouds))
content = yaml.safe_load(open(clouds))
content['clouds']['production'] = content['clouds'][target_cloud]
del content['clouds'][target_cloud]
open(clouds, 'w').write(yaml.dump(content))

4
enough/common/dotenough.py

@ -16,7 +16,7 @@ class Hosts(object):
def load(self):
if os.path.exists(self.f):
self.hosts = yaml.load(open(self.f).read())['all']['hosts']
self.hosts = yaml.safe_load(open(self.f).read())['all']['hosts']
else:
self.hosts = {}
return self
@ -116,7 +116,7 @@ class DotEnough(object):
def service_add_to_group(self, service, host):
s = f'{self.config_dir}/inventory/services.yml'
if os.path.exists(s):
services = yaml.load(open(s).read())
services = yaml.safe_load(open(s).read())
else:
services = {}
group = self.service2group(service)

2
enough/common/openstack.py

@ -333,7 +333,7 @@ class OpenStack(OpenStackBase):
def __init__(self, config_dir, **kwargs):
super().__init__(config_dir, **kwargs)
self.config = yaml.load(open(self.config_file))
self.config = yaml.safe_load(open(self.config_file))
@retry(OpenStackLeftovers, tries=7)
def destroy_everything(self, prefix):

2
playbooks/api/tests/test_api.py

@ -17,7 +17,7 @@ testinfra_hosts = ['ansible://gitlab-host']
def get_domain(inventory):
vars_dir = f'{inventory}/group_vars/all'
return yaml.load(open(vars_dir + '/domain.yml'))['domain']
return yaml.safe_load(open(vars_dir + '/domain.yml'))['domain']
def api_sign_in(pytestconfig, host):

2
playbooks/gitlab/tests/gitlab_utils.py

@ -2,6 +2,6 @@ import yaml
def get_password():
variables = yaml.load(open(
variables = yaml.safe_load(open(
'inventory/group_vars/gitlab/gitlab.yml'))
return variables['gitlab_password']

2
playbooks/icinga/tests/test_icinga_checks.py

@ -31,7 +31,7 @@ class TestChecks(IcingaHelper):
expected_version = host_vars.get('icinga_version')
if not expected_version:
icinga2_common_defaults = 'playbooks/icinga/roles/icinga2_common/defaults/main.yml'
expected_version = yaml.load(open(icinga2_common_defaults))['icinga_version']
expected_version = yaml.safe_load(open(icinga2_common_defaults))['icinga_version']
expected_version = expected_version.rsplit('.', 1)[0]
assert re.search(expected_version, version)

2
playbooks/icinga/tests/test_icingaweb.py

@ -8,7 +8,7 @@ testinfra_hosts = ['ansible://bind-host']
def get_address(inventory):
vars_dir = f'{inventory}/group_vars/all'
return 'icinga.' + yaml.load(
return 'icinga.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']

2
playbooks/icinga/tests/test_letsencrypt.py

@ -8,7 +8,7 @@ testinfra_hosts = ['ansible://icinga-host']
def get_address(inventory):
vars_dir = f'{inventory}/group_vars/all'
return 'icinga.' + yaml.load(
return 'icinga.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']

2
playbooks/openedx/tests/test_openedx.py

@ -5,7 +5,7 @@ import yaml
def get_address(inventory):
vars_dir = f'{inventory}/group_vars/all'
return 'https://openedx.' + yaml.load(
return 'https://openedx.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']

2
playbooks/psono/tests/test_psono.py

@ -5,7 +5,7 @@ import yaml
def get_address(inventory):
vars_dir = f'{inventory}/group_vars/all'
return 'https://psono.' + yaml.load(
return 'https://psono.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']

2
playbooks/wazuh/tests/test_wazuh.py

@ -20,7 +20,7 @@ class Wazuh(object):
def get_address(self, inventory):
vars_dir = f'{inventory}/group_vars/all'
return 'wazuh.' + yaml.load(
return 'wazuh.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']
def get_check_times(self, type):

2
playbooks/weblate/tests/test_weblate.py

@ -5,7 +5,7 @@ import yaml
def get_address(inventory):
vars_dir = f'{inventory}/group_vars/all'
return 'https://weblate.' + yaml.load(
return 'https://weblate.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']

2
playbooks/wordpress/tests/test_wordpress.py

@ -5,7 +5,7 @@ import yaml
def get_address(inventory):
vars_dir = f'{inventory}/group_vars/all'
return 'https://wordpress.' + yaml.load(
return 'https://wordpress.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']

4
tests/enough/common/test_ansible_utils.py

@ -83,7 +83,7 @@ def test_get_hostvars_unknown_variable():
def test_get_variable():
test_inventory = 'tests/enough/common/test_ansible_utils/variables_inventory'
expected = yaml.load(open(f'{test_inventory}/host_vars/api-host.yml'))
expected = yaml.safe_load(open(f'{test_inventory}/host_vars/api-host.yml'))
variable = 'api_admin_password'
ansible = ansible_utils.Ansible(settings.CONFIG_DIR, settings.SHARE_DIR, [test_inventory])
value = ansible.get_variable(variable, 'api-host')
@ -91,7 +91,7 @@ def test_get_variable():
def test_get_role_variable():
defaults = yaml.load(open('playbooks/api/roles/api/defaults/main.yml'))
defaults = yaml.safe_load(open('playbooks/api/roles/api/defaults/main.yml'))
variable = 'api_admin_password'
playbook = ansible_utils.Playbook(settings.CONFIG_DIR, settings.SHARE_DIR)
value = playbook.get_role_variable('api', variable, 'api-host')

6
tests/enough/common/test_dotenough.py

@ -137,7 +137,7 @@ if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi
assert DotEnoughOpenStack.openrc2clouds(
openrc_file, clouds_file) == expected['clouds']['production']
assert yaml.load(open(clouds_file)) == expected
assert yaml.safe_load(open(clouds_file)) == expected
os.unlink(openrc_file)
os.unlink(clouds_file)
@ -185,7 +185,7 @@ export OS_IDENTITY_API_VERSION=3
assert DotEnoughOpenStack.openrc2clouds(
openrc_file, clouds_file) == expected['clouds']['production']
assert yaml.load(open(clouds_file)) == expected
assert yaml.safe_load(open(clouds_file)) == expected
os.unlink(clouds_file)
expected['clouds']['production']['auth']['password'] = 'PLACEHOLDER'
@ -202,7 +202,7 @@ export OS_REGION_NAME="{region_name}"
assert DotEnoughOpenStack.openrc2clouds(
openrc_file, clouds_file) == expected['clouds']['production']
assert yaml.load(open(clouds_file)) == expected
assert yaml.safe_load(open(clouds_file)) == expected
os.unlink(clouds_file)
assert DotEnoughOpenStack.set_missing_config_file_from_openrc(openrc_file, clouds_file) is True

2
tests/enough/common/test_init.py

@ -325,7 +325,7 @@ def test_replace_production(tmpdir):
clouds_path = f'{tmpdir}/clouds.yml'
open(clouds_path, 'w').write(yaml.dump(clouds))
Enough.replace_production(clouds_path, target_cloud)
clouds = yaml.load(open(clouds_path))
clouds = yaml.safe_load(open(clouds_path))
assert clouds['clouds']['production'] == 'CLONE'
assert target_cloud not in clouds['clouds']

2
tests/icinga_helper.py

@ -58,7 +58,7 @@ class IcingaHelper(object):
def get_address(self):
if get_driver() == 'openstack':
vars_dir = f'{self.inventory}/group_vars/all'
host = 'icinga.' + yaml.load(
host = 'icinga.' + yaml.safe_load(
open(vars_dir + '/domain.yml'))['domain']
else:
host = testinfra.get_host('ansible://icinga-service-group',

2
tests/infrastructure.py

@ -5,4 +5,4 @@ from enough import settings
def get_driver():
vars_dir = f'{settings.CONFIG_DIR}/inventory/group_vars/all'
return yaml.load(open(f'{vars_dir}/infrastructure.yml'))['infrastructure_driver']
return yaml.safe_load(open(f'{vars_dir}/infrastructure.yml'))['infrastructure_driver']

Loading…
Cancel
Save