Exemple #1
0
 def test_manifest_must_have_tests(self):
     with open(self._manifest_path, 'w') as fp:
         fp.write('module_name: modules.bar.bar_module\n'
                  'container_version: 1.3\n')
     with self.assertRaises(KeyError):
         # pylint: disable=expression-not-assigned
         yaml_files.ModuleManifest(self._manifest_path).module_name
Exemple #2
0
 def test_minimal_manifest(self):
     with open(self._manifest_path, 'w') as fp:
         fp.write('module_name: modules.foo.foo_module\n'
                  'container_version: 1.2.3\n'
                  'tests:\n'
                  '  this: 1\n'
                  '  that: 2\n')
     manifest = yaml_files.ModuleManifest(self._manifest_path)
     self.assertEquals(manifest.module_name, 'foo')
     self.assertEquals(manifest.main_module, 'modules.foo.foo_module')
     self.assertEquals(manifest.third_party_libraries, {})
     self.assertEquals(manifest.appengine_libraries, {})
     self.assertEquals(manifest.tests, {'this': 1, 'that': 2})
Exemple #3
0
def _install_if_needed(app_yaml, name, module_install_dir, coursebuilder_home):
    # Verify version compatibility before attempting installation.
    coursebuilder_version = app_yaml.get_env('GCB_PRODUCT_VERSION')
    module = yaml_files.ModuleManifest(
        os.path.join(module_install_dir, _MANIFEST_NAME))
    module.assert_version_compatibility(coursebuilder_version)

    # This is the best we can do as far as verifying that a module has been
    # installed.  Modules have quite a bit of free rein as far as what-all
    # they may or may not do -- setting up $CB/modules/<modulename> is the
    # only hard requirement.  Note that this may even be a softlink, so
    # we just test for existence, not is-a-directory.
    if os.path.exists(os.path.join(coursebuilder_home, 'modules', name)):
        return module
    _LOG.info('Installing module %s', name)

    # Verify setup script exists and give a nice error message if not (rather
    # than letting _run_process emit an obscure error).
    install_script_path = os.path.join(module_install_dir, 'scripts',
                                       'setup.sh')
    _assert_path_exists(
        install_script_path,
        'Modules are expected to provide a script to perform installation of '
        'the module at <module-root>/scripts/setup.sh  No such file was found '
        'in module %s' % name)

    # Have $PWD set to the install directory for the module when calling
    # setup.sh, just in case the setup script needs to discover its own
    # location in order to set up softlinks.
    cwd = os.getcwd()
    try:
        os.chdir(module_install_dir)
        _run_process(['bash', install_script_path, '-d', coursebuilder_home],
                     patience_seconds=_SETUP_SH_EXECUTION_MAX_SECONDS)
    finally:
        os.chdir(cwd)

    # Verify setup script exists and give a nice error message if not (rather
    # than letting _run_process emit an obscure error).
    install_script_path = os.path.join(module_install_dir, 'scripts',
                                       'setup.sh')
    init_file_path = os.path.join(coursebuilder_home, 'modules', name,
                                  '__init__.py')
    _assert_path_exists(
        init_file_path,
        'After installing module %s, there should have been an __init__.py '
        'file present at the path %s, but there was not.' %
        (name, init_file_path))

    return module
Exemple #4
0
    def test_version_compatibility(self):
        with open(self._manifest_path, 'w') as fp:
            fp.write('module_name: modules.foo.foo_module\n'
                     'container_version: 1.2.3\n'
                     'tests:\n'
                     '  this: 1\n'
                     '  that: 2\n')
        manifest = yaml_files.ModuleManifest(self._manifest_path)
        manifest.assert_version_compatibility('1.2.3')
        manifest.assert_version_compatibility('1.2.4')
        manifest.assert_version_compatibility('1.3.0')
        manifest.assert_version_compatibility('2.0.0')

        with self.assertRaises(ValueError):
            manifest.assert_version_compatibility('1.2.2')
        with self.assertRaises(ValueError):
            manifest.assert_version_compatibility('1.1.9')
        with self.assertRaises(ValueError):
            manifest.assert_version_compatibility('0.9.9')
Exemple #5
0
 def test_module_name_must_start_with_modules(self):
     with open(self._manifest_path, 'w') as fp:
         fp.write('module_name: bar.baz\n')
     with self.assertRaises(ValueError):
         # pylint: disable=expression-not-assigned
         yaml_files.ModuleManifest(self._manifest_path).module_name
Exemple #6
0
 def test_manifest_must_contain_module(self):
     with open(self._manifest_path, 'w') as fp:
         fp.write('foo: bar\n')
     with self.assertRaises(KeyError):
         # pylint: disable=expression-not-assigned
         yaml_files.ModuleManifest(self._manifest_path).module_name
Exemple #7
0
 def test_module_name_must_name_full_python_module(self):
     with open(self._manifest_path, 'w') as fp:
         fp.write('module_name: bar\n')
     with self.assertRaises(ValueError):
         # pylint: disable-msg=expression-not-assigned
         yaml_files.ModuleManifest(self._manifest_path).module_name