Browse Source

enough: add 'clone' to clouds.yml

keep-around/f99a43700a779f71e3a34fac7f749d436e43ce90
Loïc Dachary 1 year ago
committed by Loic Dachary
parent
commit
6b028dcaba
Signed by: dachary GPG Key ID: 992D23B392F9E4F2
  1. 6
      enough/common/dotenough.py
  2. 37
      tests/enough/common/test_dotenough.py
  3. 4
      tests/run-tests.sh

6
enough/common/dotenough.py

@ -1,3 +1,4 @@
import copy
import os
import re
import sh
@ -157,9 +158,12 @@ class DotEnoughOpenStack(DotEnough):
c['auth']['username'] = v
elif k == 'OS_PASSWORD' and v != '$OS_PASSWORD_INPUT':
c['auth']['password'] = v
clone = copy.deepcopy(c)
clone['region_name'] = 'DE1'
open(clouds, 'w').write(yaml.dump({
'clouds': {
'ovh': c
'production': c,
'clone': clone,
}
}))
return c

37
tests/enough/common/test_dotenough.py

@ -42,19 +42,25 @@ def test_openstack_openrc2clouds(tmpdir):
username = 'username'
password = 'password'
region_name = 'region_name'
clone_region_name = 'DE1'
auth = {
'auth_url': auth_url,
'project_name': project_name,
'project_id': project_id,
'user_domain_name': "Default",
'username': username,
'password': password,
}
expected = {
'clouds': {
'ovh': {
'production': {
'region_name': region_name,
'auth': {
'auth_url': auth_url,
'project_name': project_name,
'project_id': project_id,
'user_domain_name': "Default",
'username': username,
'password': password,
}
'auth': auth,
},
'clone': {
'region_name': clone_region_name,
'auth': auth,
}
}
}
@ -97,7 +103,8 @@ if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi
"""
open(openrc_file, 'w').write(openrc_1)
assert DotEnoughOpenStack.openrc2clouds(openrc_file, clouds_file) == expected['clouds']['ovh']
assert DotEnoughOpenStack.openrc2clouds(
openrc_file, clouds_file) == expected['clouds']['production']
assert yaml.load(open(clouds_file)) == expected
os.unlink(openrc_file)
os.unlink(clouds_file)
@ -144,11 +151,12 @@ export OS_IDENTITY_API_VERSION=3
"""
open(openrc_file, 'w').write(openrc_2)
assert DotEnoughOpenStack.openrc2clouds(openrc_file, clouds_file) == expected['clouds']['ovh']
assert DotEnoughOpenStack.openrc2clouds(
openrc_file, clouds_file) == expected['clouds']['production']
assert yaml.load(open(clouds_file)) == expected
os.unlink(clouds_file)
expected['clouds']['ovh']['auth']['password'] = 'PLACEHOLDER'
expected['clouds']['production']['auth']['password'] = 'PLACEHOLDER'
openrc_3 = f"""
export OS_AUTH_URL={auth_url}
export OS_PROJECT_ID={project_id}
@ -160,7 +168,8 @@ export OS_REGION_NAME="{region_name}"
"""
open(openrc_file, 'w').write(openrc_3)
assert DotEnoughOpenStack.openrc2clouds(openrc_file, clouds_file) == expected['clouds']['ovh']
assert DotEnoughOpenStack.openrc2clouds(
openrc_file, clouds_file) == expected['clouds']['production']
assert yaml.load(open(clouds_file)) == expected
os.unlink(clouds_file)

4
tests/run-tests.sh

@ -33,6 +33,10 @@ clouds:
username: "$OS_USERNAME"
password: "$OS_PASSWORD"
region_name: "$OS_REGION_NAME"
clone:
auth:
<<: *os_auth
region_name: "DE1"
EOF
cp tests/clouds.yml inventory/group_vars/all/clouds.yml
else

Loading…
Cancel
Save