Пример #1
0
    def test_package_import_multiple(self, rm):
        args = TestArgs()

        args.filename = ["io.test.apps.test_application",
                         "http://127.0.0.1/test_app2.zip", ]
        args.categories = None
        args.is_public = False
        args.murano_repo_url = "http://127.0.0.1"

        rm.get(args.murano_repo_url + '/apps/' + args.filename[0] + '.zip',
               body=make_pkg({'FullName': 'first_app'}))

        rm.get(args.filename[1],
               body=make_pkg({'FullName': 'second_app'}))

        v1_shell.do_package_import(self.client, args)

        self.assertTrue(self.client.packages.create.called)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
            ], any_order=True,
        )
    def test_package_import_multiple(self, rm):
        args = TestArgs()

        args.filename = ["io.test.apps.test_application",
                         "http://127.0.0.1/test_app2.zip", ]
        args.categories = None
        args.is_public = False
        args.murano_repo_url = "http://127.0.0.1"

        rm.get(args.murano_repo_url + '/apps/' + args.filename[0] + '.zip',
               body=make_pkg({'FullName': 'first_app'}))

        rm.get(args.filename[1],
               body=make_pkg({'FullName': 'second_app'}))

        v1_shell.do_package_import(self.client, args)

        self.assertTrue(self.client.packages.create.called)

        self.client.packages.create.assert_has_calls(
            [
                mock.call({'is_public': False}, {'first_app': mock.ANY}),
                mock.call({'is_public': False}, {'second_app': mock.ANY}),
            ], any_order=True,
        )
Пример #3
0
def import_application_package(repo_url,package_name):
    
    try:
        auth_token = get_auth_token()
        #initializing MuranoClient
        mc = v1_client.Client(endpoint=endpoint, token= auth_token,timeout = 600)
        #mc.environments.list()
        #mc.environments.get(environment_id='b93d63bde2b3423cb1f8d5e54aeb99a3')
        
        args = InitArgs()    
        ###filename is URL###
        #args.filename = {"http://storage.apps.openstack.org/apps/io.murano.apps.apache.ApacheHttpServer.zip"}
        args.murano_repo_url = ''
        
        ###filename is name and repo_url###
        #args.filename = {"io.murano.apps.apache.ApacheHttpServer"}
        #args.murano_repo_url = 'http://storage.apps.openstack.org/'    
        args.filename = {package_name}
        args.murano_repo_url = repo_url
        
        ###filename is localpath###
        #args.filename = {"C:/Users/admin/Downloads/io.murano.apps.apache.ApacheHttpServer.zip"}
        #args.murano_repo_url = ''    
        args.categories = None
        args.is_public = False
        args.package_version = ''    
        args.exists_action = 'u' #(s)kip, (u)pdate, (a)bort    
        
        
        response = v1_shell.do_package_import(mc, args)
        
        '''
            Check whether the package imported properly
        '''        
        
        if os.path.exists(package_name):
            package_name = os.path.basename(package_name)
            package_name = os.path.splitext(package_name)[0]
            
        package_generator = mc.packages.filter(fqn = package_name)
        #pp = mc.packages.list()
        package_obj =  package_generator.next()        
        package_info = package_obj.__dict__
        print package_info
        #print package_info['id']
        #print package_info['class_definitions']['id']
        
        if package_info['id']: 
            return {'status': 'success', 'msg': 'Package imported successfully','response':package_info}       
        else:
            return {'status': 'failed', 'msg': 'Error occurred,while importing the package'}
        
    except Exception as e:
        LOG.error("Error  occurred,"
                          " while importing the package".format(e))
        return {'status': 'failed', 'msg': 'Error Occurred,while importing the package'}
        #raise   
    
    return {'status': 'success', 'msg': 'Package imported successfully'}
    def test_package_import_url(self, rm, from_file):
        args = TestArgs()
        args.filename = ["http://127.0.0.1/test_package.zip"]
        args.categories = None
        args.is_public = False

        pkg = make_pkg({'FullName': 'test_package'})
        from_file.return_value = utils.Package(utils.File(pkg))

        rm.get(args.filename[0], body=make_pkg({'FullName': 'test_package'}))

        v1_shell.do_package_import(self.client, args)

        self.client.packages.create.assert_called_once_with(
            {'is_public': False},
            {'test_package': mock.ANY},
        )
    def test_package_import(self, from_file):
        args = TestArgs()
        with tempfile.NamedTemporaryFile() as f:
            RESULT_PACKAGE = f.name
            args.filename = [RESULT_PACKAGE]
            args.categories = ['Cat1', 'Cat2 with space']
            args.is_public = True

            pkg = make_pkg({'FullName': RESULT_PACKAGE})
            from_file.return_value = utils.Package(utils.File(pkg))

            v1_shell.do_package_import(self.client, args)

            self.client.packages.create.assert_called_once_with({
                'categories': ['Cat1', 'Cat2 with space'],
                'is_public': True
            }, {RESULT_PACKAGE: mock.ANY},)
Пример #6
0
    def test_package_import_url(self, rm, from_file):
        args = TestArgs()
        args.filename = ["http://127.0.0.1/test_package.zip"]
        args.categories = None
        args.is_public = False

        pkg = make_pkg({'FullName': 'test_package'})
        from_file.return_value = utils.Package(utils.File(pkg))

        rm.get(args.filename[0], body=make_pkg({'FullName': 'test_package'}))

        v1_shell.do_package_import(self.client, args)

        self.client.packages.create.assert_called_once_with(
            {'is_public': False},
            {'test_package': mock.ANY},
        )
Пример #7
0
    def test_package_import(self, from_file):
        args = TestArgs()
        with tempfile.NamedTemporaryFile() as f:
            RESULT_PACKAGE = f.name
            args.filename = [RESULT_PACKAGE]
            args.categories = ['Cat1', 'Cat2 with space']
            args.is_public = True

            pkg = make_pkg({'FullName': RESULT_PACKAGE})
            from_file.return_value = utils.Package(utils.File(pkg))

            v1_shell.do_package_import(self.client, args)

            self.client.packages.create.assert_called_once_with({
                'categories': ['Cat1', 'Cat2 with space'],
                'is_public': True
            }, {RESULT_PACKAGE: mock.ANY},)
    def _test_conflict(self,
                       packages, from_file, raw_input_mock,
                       input_action, exists_action=''):
        packages.create = mock.MagicMock(
            side_effect=[common_exceptions.HTTPConflict("Conflict"), None])

        packages.filter.return_value = [mock.Mock(id='test_id')]

        raw_input_mock.return_value = input_action
        args = TestArgs()
        args.exists_action = exists_action
        with tempfile.NamedTemporaryFile() as f:
            args.filename = [f.name]

            pkg = make_pkg({'FullName': f.name})
            from_file.return_value = utils.Package(utils.File(pkg))

            v1_shell.do_package_import(self.client, args)
            return f.name
Пример #9
0
    def _test_conflict(self,
                       packages, from_file, raw_input_mock,
                       input_action, exists_action=''):
        packages.create = mock.MagicMock(
            side_effect=[common_exceptions.HTTPConflict("Conflict"), None])

        packages.filter.return_value = [mock.Mock(id='test_id')]

        raw_input_mock.return_value = input_action
        args = TestArgs()
        args.exists_action = exists_action
        with tempfile.NamedTemporaryFile() as f:
            args.filename = [f.name]

            pkg = make_pkg({'FullName': f.name})
            from_file.return_value = utils.Package(utils.File(pkg))

            v1_shell.do_package_import(self.client, args)
            return f.name
    def test_package_import_by_name(self, rm, from_file):
        args = TestArgs()

        args.filename = ["io.test.apps.test_application"]
        args.categories = None
        args.is_public = False
        args.murano_repo_url = "http://127.0.0.1"

        pkg = make_pkg({'FullName': args.filename[0]})
        from_file.return_value = utils.Package(utils.File(pkg))

        rm.get(args.murano_repo_url + '/apps/' + args.filename[0] + '.zip',
               body=make_pkg({'FullName': 'first_app'}))

        v1_shell.do_package_import(self.client, args)

        self.assertTrue(self.client.packages.create.called)
        self.client.packages.create.assert_called_once_with(
            {'is_public': False},
            {args.filename[0]: mock.ANY},
        )
Пример #11
0
    def test_package_import_by_name(self, rm, from_file):
        args = TestArgs()

        args.filename = ["io.test.apps.test_application"]
        args.categories = None
        args.is_public = False
        args.murano_repo_url = "http://127.0.0.1"

        pkg = make_pkg({'FullName': args.filename[0]})
        from_file.return_value = utils.Package(utils.File(pkg))

        rm.get(args.murano_repo_url + '/apps/' + args.filename[0] + '.zip',
               body=make_pkg({'FullName': 'first_app'}))

        v1_shell.do_package_import(self.client, args)

        self.assertTrue(self.client.packages.create.called)
        self.client.packages.create.assert_called_once_with(
            {'is_public': False},
            {args.filename[0]: mock.ANY},
        )