예제 #1
0
    def test_register_pack_pack_ref(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()

        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_1': PACK_PATH_1,
            'dummy_pack_6': PACK_PATH_6
        }
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Ref is provided
        pack_db = Pack.get_by_name('dummy_pack_6')
        self.assertEqual(pack_db.ref, 'dummy_pack_6_ref')
        self.assertEqual(len(pack_db.contributors), 0)

        # Ref is not provided, directory name should be used
        pack_db = Pack.get_by_name('dummy_pack_1')
        self.assertEqual(pack_db.ref, 'dummy_pack_1')

        # "ref" is not provided, but "name" is
        registrar._register_pack_db(pack_name=None, pack_dir=PACK_PATH_7)

        pack_db = Pack.get_by_name('dummy_pack_7_name')
        self.assertEqual(pack_db.ref, 'dummy_pack_7_name')

        # "ref" is not provided and "name" contains invalid characters
        expected_msg = 'contains invalid characters'
        self.assertRaisesRegexp(ValueError, expected_msg, registrar._register_pack_db,
                                pack_name=None, pack_dir=PACK_PATH_8)
예제 #2
0
    def test_register_pack_pack_ref(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()

        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_1': PACK_PATH_1,
            'dummy_pack_6': PACK_PATH_6
        }
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Ref is provided
        pack_db = Pack.get_by_name('dummy_pack_6')
        self.assertEqual(pack_db.ref, 'dummy_pack_6_ref')
        self.assertEqual(len(pack_dbs[0].contributors), 0)

        # Ref is not provided, directory name should be used
        pack_db = Pack.get_by_name('dummy_pack_1')
        self.assertEqual(pack_db.ref, 'dummy_pack_1')

        # "ref" is not provided, but "name" is
        registrar._register_pack_db(pack_name=None, pack_dir=PACK_PATH_7)

        pack_db = Pack.get_by_name('dummy_pack_7_name')
        self.assertEqual(pack_db.ref, 'dummy_pack_7_name')

        # "ref" is not provided and "name" contains invalid characters
        expected_msg = 'contains invalid characters'
        self.assertRaisesRegexp(ValueError, expected_msg, registrar._register_pack_db,
                                pack_name=None, pack_dir=PACK_PATH_8)
예제 #3
0
파일: unload.py 프로젝트: yetudada/st2
    def _delete_pack_db_object(self, pack):
        pack_db = None

        # 1. Try by ref
        try:
            pack_db = Pack.get_by_ref(value=pack)
        except StackStormDBObjectNotFoundError:
            pack_db = None

        # 2. Try by name (here for backward compatibility)
        # TODO: This shouldn't be needed in the future, remove it in v2.1 or similar
        if not pack_db:
            try:
                pack_db = Pack.get_by_name(value=pack)
            except StackStormDBObjectNotFoundError:
                pack_db = None

        if not pack_db:
            self.logger.exception('Pack DB object not found')
            return

        try:
            Pack.delete(pack_db)
        except:
            self.logger.exception('Failed to remove DB object %s.', pack_db)
예제 #4
0
    def test_register_pack_pack_stackstorm_version_and_future_parameters(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_9': PACK_PATH_9
        }
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Dependencies, stackstorm_version and future values
        pack_db = Pack.get_by_name('dummy_pack_9_deps')
        self.assertEqual(pack_db.dependencies, ['core=0.2.0'])
        self.assertEqual(pack_db.stackstorm_version, '>=1.6.0, <2.2.0')
        self.assertEqual(pack_db.system, {'centos': {'foo': '>= 1.0'}})

        # Note: We only store paramters which are defined in the schema, all other custom user
        # defined attributes are ignored
        self.assertTrue(not hasattr(pack_db, 'future'))
        self.assertTrue(not hasattr(pack_db, 'this'))

        # Wrong characters in the required st2 version
        expected_msg = "'wrongstackstormversion' does not match"
        self.assertRaisesRegexp(ValidationError,
                                expected_msg,
                                registrar._register_pack_db,
                                pack_name=None,
                                pack_dir=PACK_PATH_10)
예제 #5
0
    def test_register_pack_pack_stackstorm_version_and_future_parameters(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_9': PACK_PATH_9}
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Dependencies, stackstorm_version and future values
        pack_db = Pack.get_by_name('dummy_pack_9_deps')
        self.assertEqual(pack_db.dependencies, ['core=0.2.0'])
        self.assertEqual(pack_db.stackstorm_version, '>=1.6.0, <2.2.0')
        self.assertEqual(pack_db.system, {'centos': {'foo': '>= 1.0'}})
        self.assertEqual(pack_db.python_versions, ['2', '3'])

        # Note: We only store parameters which are defined in the schema, all other custom user
        # defined attributes are ignored
        self.assertTrue(not hasattr(pack_db, 'future'))
        self.assertTrue(not hasattr(pack_db, 'this'))

        # Wrong characters in the required st2 version
        expected_msg = "'wrongstackstormversion' does not match"
        self.assertRaisesRegexp(ValidationError, expected_msg, registrar._register_pack_db,
                                pack_name=None, pack_dir=PACK_PATH_10)
예제 #6
0
파일: unload.py 프로젝트: nzlosh/st2
    def _delete_pack_db_object(self, pack):
        pack_db = None

        # 1. Try by ref
        try:
            pack_db = Pack.get_by_ref(value=pack)
        except StackStormDBObjectNotFoundError:
            pack_db = None

        # 2. Try by name (here for backward compatibility)
        # TODO: This shouldn't be needed in the future, remove it in v2.1 or similar
        if not pack_db:
            try:
                pack_db = Pack.get_by_name(value=pack)
            except StackStormDBObjectNotFoundError:
                pack_db = None

        if not pack_db:
            self.logger.exception('Pack DB object not found')
            return

        try:
            Pack.delete(pack_db)
        except:
            self.logger.exception('Failed to remove DB object %s.', pack_db)
예제 #7
0
파일: unload.py 프로젝트: Bala96/st2
    def _delete_pack_db_object(self, pack):
        try:
            pack_db = Pack.get_by_name(value=pack)
        except StackStormDBObjectNotFoundError:
            self.logger.exception('Pack DB object not found')
            return

        try:
            Pack.delete(pack_db)
        except:
            self.logger.exception('Failed to remove DB object %s.', pack_db)
예제 #8
0
    def _delete_pack_db_object(self, pack):
        try:
            pack_db = Pack.get_by_name(value=pack)
        except ValueError:
            self.logger.exception('Pack DB object not found')
            return

        try:
            Pack.delete(pack_db)
        except:
            self.logger.exception('Failed to remove DB object %s.', pack_db)
예제 #9
0
    def test_register_pack_old_style_non_semver_version_is_normalized_to_valid_version(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_11': PACK_PATH_11}
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Non-semver valid version 0.2 should be normalize to 0.2.0
        pack_db = Pack.get_by_name('dummy_pack_11')
        self.assertEqual(pack_db.version, '0.2.0')
예제 #10
0
    def test_register_pack_old_style_non_semver_version_is_normalized_to_valid_version(self):
        # Verify DB is empty
        pack_dbs = Pack.get_all()
        self.assertEqual(len(pack_dbs), 0)

        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {'dummy_pack_11': PACK_PATH_11}
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Non-semver valid version 0.2 should be normalize to 0.2.0
        pack_db = Pack.get_by_name('dummy_pack_11')
        self.assertEqual(pack_db.version, '0.2.0')
예제 #11
0
    def test_register_pack_arbitrary_properties_are_allowed(self):
        # Test registering a pack which has "arbitrary" properties in pack.yaml
        # We support this use-case (ignore properties which are not defined on the PackAPI model)
        # so we can add new attributes in a new version without breaking existing installations.
        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_20': PACK_PATH_20,
        }
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Ref is provided
        pack_db = Pack.get_by_name('dummy_pack_20')
        self.assertEqual(pack_db.ref, 'dummy_pack_20_ref')
        self.assertEqual(len(pack_db.contributors), 0)
예제 #12
0
    def test_register_pack_arbitrary_properties_are_allowed(self):
        # Test registering a pack which has "arbitrary" properties in pack.yaml
        # We support this use-case (ignore properties which are not defined on the PackAPI model)
        # so we can add new attributes in a new version without breaking existing installations.
        registrar = ResourceRegistrar(use_pack_cache=False)
        registrar._pack_loader.get_packs = mock.Mock()
        registrar._pack_loader.get_packs.return_value = {
            'dummy_pack_20': PACK_PATH_20,
        }
        packs_base_paths = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=packs_base_paths)

        # Ref is provided
        pack_db = Pack.get_by_name('dummy_pack_20')
        self.assertEqual(pack_db.ref, 'dummy_pack_20_ref')
        self.assertEqual(len(pack_db.contributors), 0)