Skip to content

Expose datasafety link and text as install options. #90

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions mig/install/MiGserver-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -784,5 +784,5 @@ logo_right = /images/skin/__SKIN__/logo-right.png
#credits_text = 2003-2023, <a href="https://www.migrid.org">The MiG Project</a>
#credits_image = /images/copyright.png
# Optional data safety notice and popup on Files page
#datasafety_link =
#datasafety_text =
datasafety_link = __DATASAFETY_LINK__
datasafety_text = __DATASAFETY_TEXT__
4 changes: 3 additions & 1 deletion mig/install/generateconfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def usage(options):
'quota_backend',
'ca_fqdn',
'ca_user',
'ca_smtp'
'ca_smtp',
'datasafety_link',
'datasafety_text',
]
int_names = [
'cert_valid_days',
Expand Down
6 changes: 6 additions & 0 deletions mig/shared/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ def generate_confs(
ca_fqdn='',
ca_user='mig-ca',
ca_smtp='localhost',
datasafety_link='',
datasafety_text='',
_getcwd=os.getcwd,
_getpwnam=pwd.getpwnam,
_prepare=None,
Expand Down Expand Up @@ -793,6 +795,8 @@ def _generate_confs_prepare(
ca_fqdn,
ca_user,
ca_smtp,
datasafety_link,
datasafety_text,
):
"""Prepate conf generator run"""
user_dict = {}
Expand Down Expand Up @@ -1039,6 +1043,8 @@ def _generate_confs_prepare(
user_dict['__CA_FQDN__'] = ca_fqdn
user_dict['__CA_USER__'] = ca_user
user_dict['__CA_SMTP__'] = ca_smtp
user_dict['__DATASAFETY_LINK__'] = datasafety_link
user_dict['__DATASAFETY_TEXT__'] = datasafety_text

user_dict['__MIG_USER__'] = "%s" % (options['user_uname'])
user_dict['__MIG_GROUP__'] = "%s" % (options['user_group'])
Expand Down
4 changes: 2 additions & 2 deletions tests/fixture/confs-stdlocal/MiGserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -784,5 +784,5 @@ logo_right = /images/skin/migrid-basic/logo-right.png
#credits_text = 2003-2023, <a href="https://www.migrid.org">The MiG Project</a>
#credits_image = /images/copyright.png
# Optional data safety notice and popup on Files page
#datasafety_link =
#datasafety_text =
datasafety_link =
datasafety_text =
6 changes: 6 additions & 0 deletions tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ def fixturepath(relative_path):
return tmp_path


def outputpath(relative_path):
assert not os.path.isabs(relative_path)
tmp_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
return tmp_path


def temppath(relative_path, test_case, skip_clean=False):
assert isinstance(test_case, MigTestCase)
tmp_path = os.path.join(TEST_OUTPUT_DIR, relative_path)
Expand Down
42 changes: 41 additions & 1 deletion tests/test_mig_shared_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@

"""Unit tests for the migrid module pointed to in the filename"""

from past.builtins import basestring
import binascii
from configparser import ConfigParser, NoSectionError, NoOptionError
import difflib
import io
import os
import pwd
import sys

sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), ".")))

from support import MIG_BASE, MigTestCase, testmain, temppath, cleanpath, fixturepath
from support import MIG_BASE, MigTestCase, testmain, temppath, cleanpath, fixturepath, outputpath

from mig.shared.defaults import keyword_auto
from mig.shared.install import determine_timezone, generate_confs
Expand Down Expand Up @@ -109,6 +112,21 @@ def exists_timedatectl(value):
class MigSharedInstall__generate_confs(MigTestCase):
"""Unit test helper for the migrid code pointed to in class name"""

def assertConfigKey(self, generated, section, key, expected):
if isinstance(generated, basestring):
with io.open(generated) as config_file:
generated = ConfigParser()
generated.read_file(config_file)

try:
actual = generated.get(section, key)
except NoSectionError:
raise AssertionError("no such section: %s" % (section,))
except NoOptionError:
raise AssertionError("on such option: %s in %s" % (key, section))

self.assertEqual(actual, expected)

def test_creates_output_directory_and_adds_active_symlink(self):
symlink_path = temppath('confs', self)
cleanpath('confs-foobar', self)
Expand Down Expand Up @@ -164,6 +182,28 @@ def test_creates_output_directory_containing_a_standard_local_configuration(self
expected_file = os.path.join(fixture_dir, file_name)
self.assertFileContentIdentical(actual_file, expected_file)

def test_creates_output_files_with_datasafety(self):
fixture_dir = fixturepath("confs-stdlocal")
expected_generated_dir = cleanpath('confs-stdlocal', self)
symlink_path = temppath('confs', self)

generate_confs(
destination=symlink_path,
destination_suffix='-stdlocal',
datasafety_link='TEST_DATASAFETY_LINK',
datasafety_text='TEST_DATASAFETY_TEXT',
_getpwnam=create_dummy_gpwnam(4321, 1234),
)

relative_file = 'confs-stdlocal/MiGserver.conf'
self.assertPathExists('confs-stdlocal/MiGserver.conf')

actual_file = outputpath(relative_file)
self.assertConfigKey(
actual_file, 'SITE', 'datasafety_link', expected='TEST_DATASAFETY_LINK')
self.assertConfigKey(
actual_file, 'SITE', 'datasafety_text', expected='TEST_DATASAFETY_TEXT')

def test_options_for_source_auto(self):
options = generate_confs(
source=keyword_auto,
Expand Down
Loading