Esempio n. 1
0
    def blueprint_deployment_test(self, user, blueprint, spec='default', image='default'):
        """
        Try to process a blueprint and return results
        :param blueprint: blueprint to deploy
        :param spec: spec to deploy
        :param image: image to deploy to
        :return: dictionary with results
        """
        LOG.debug("Sending blueprint to docker server at %s" % self.dc._url)
        b_success = True
        msg = {}
        self.dc.run_container(image)
        msg['install'] = self.run_install(blueprint)
        b_success &= msg['install']['success']
        msg['test'] = self.run_test(blueprint)
        b_success &= msg['test']['success']
        msg['deploy'] = self.run_deploy(blueprint)
        b_success &= msg['deploy']['success']

        # check execution output
        if b_success:
            msg['result'] = {
                'success': True,
                'result': "Blueprint %s successfully deployed\n" % blueprint
            }
        else:
            msg['result'] = {
                'success': False,
                'result': "Error deploying blueprint {}\n".format(blueprint)
            }
            LOG.error(_LW(msg))
        self.dc.remove_container()
        return msg
Esempio n. 2
0
 def run_container(self, user, cookbook, image_name):
     """Run and start a container based on the given image
     mounts local cookbook storage path
     :param image_name: image to run
     :return: operation status
     """
     status = True
     error = "Image successfully created: [%s]" % image_name
     self.prepare_image(image_name)
     contname = self.generate_container_name(user, cookbook, image_name)
     try:
         self.remove_container(contname, kill=True)
         container = self.dc.create_container(
             image_name,
             tty=True,
             volumes=[CONF.clients_git.repo_path],
             name=contname,
             host_config=self.dc.create_host_config(
                 binds={
                 CONF.clients_git.repo_path: {
                     'bind': CONF.clients_git.repo_path,
                     'mode': 'rw',
                     },
                 },
                 network_mode="host"
             ),
         ).get('Id')
         self.dc.start(container=container)
     except NotFound as e:
         error = "Image not found: [%s]" % image_name
         LOG.error(_LW(error))
         status = False
     except AttributeError as e:
         error = "Error creating container: [%s]" % e
         LOG.error(_LW(error))
         status = False
         # raise DockerContainerException(image=image_name)
     return status, error
Esempio n. 3
0
 def run_container(self, user, cookbook, image_name):
     """Run and start a container based on the given image
     mounts local cookbook storage path
     :param image_name: image to run
     :return: operation status
     """
     status = True
     error = "Image successfully created: [%s]" % image_name
     self.prepare_image(image_name)
     contname = self.generate_container_name(user, cookbook, image_name)
     try:
         self.remove_container(contname, kill=True)
         container = self.dc.create_container(
             image_name,
             tty=True,
             volumes=[CONF.clients_git.repo_path],
             name=contname,
             host_config=self.dc.create_host_config(binds={
                 CONF.clients_git.repo_path: {
                     'bind': CONF.clients_git.repo_path,
                     'mode': 'rw',
                 },
             },
                                                    network_mode="host"),
         ).get('Id')
         self.dc.start(container=container)
     except NotFound as e:
         error = "Image not found: [%s]" % image_name
         LOG.error(_LW(error))
         status = False
     except AttributeError as e:
         error = "Error creating container: [%s]" % e
         LOG.error(_LW(error))
         status = False
         # raise DockerContainerException(image=image_name)
     return status, error
Esempio n. 4
0
 def run_install(self, user, blueprint, image):
     """Run download and install command
     :param blueprint: blueprint to process
     :return msg: operation result
     """
     try:
         self.dc.container = self.dc.run_container(image)
         cmd_install = CONF.clients_murano.cmd_install.format(blueprint)
         resp_install = self.dc.execute_command(cmd_install)
         msg = {'success': True, 'response': resp_install}
         for line in resp_install.splitlines():
             if "ERROR" in line:
                 msg['success'] = False
         LOG.debug(_("Install result: %s") % resp_install)
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Murano install exception: %s" % e))
         raise CookbookInstallException(blueprint=blueprint)
     return msg
Esempio n. 5
0
 def run_test(self, user, blueprint, image):
     """ Test blueprint syntax
     :param blueprint: blueprint to test
     :return msg: dictionary with results and state
     """
     try:
         self.dc.container = self.dc.run_container(image)
         cmd_syntax = CONF.clients_murano.cmd_syntax.format(blueprint)
         resp_test = self.dc.execute_command(cmd_syntax)
         msg = {'success': True, 'response': resp_test}
         for line in resp_test.splitlines():
             if "ERROR" in line:
                 msg['success'] = False
         LOG.debug(_("Test result: %s") % resp_test)
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Blueprint syntax exception %s" % e))
         raise CookbookSyntaxException(blueprint=blueprint)
     return msg
Esempio n. 6
0
 def run_deploy(self, user, blueprint, spec, image):
     """ Run blueprint deployment
     :param blueprint: blueprint to deploy
     :return msg: dictionary with results and state
     """
     try:
         # launch execution
         self.dc.container = self.dc.run_container(image)
         cmd_deploy = CONF.clients_murano.cmd_deploy
         resp_launch = self.dc.execute_command(cmd_deploy)
         msg = {'success': True, 'response': resp_launch}
         LOG.debug(_("Launch result: %s") % resp_launch)
         if resp_launch is None or "FATAL" in resp_launch:
             msg['success'] = False
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Blueprint deployment exception %s" % e))
         raise CookbookDeploymentException(blueprint=blueprint)
     return msg
Esempio n. 7
0
 def run_deploy(self, user, cookbook, recipe, image):
     """ Run cookbook deployment
     :param cookbook: cookbook to deploy
     :return msg: dictionary with results and state
     """
     try:
         # launch execution
         self.dc.container = self.dc.run_container(image)
         cmd_deploy = CONF.clients_puppet.cmd_deploy
         resp_launch = self.dc.execute_command(cmd_deploy)
         msg = {'success': True, 'response': resp_launch}
         LOG.debug(_("Launch result: %s") % resp_launch)
         if resp_launch is None or "FATAL" in resp_launch:
             msg['success'] = False
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Cookbook deployment exception %s" % e))
         raise CookbookDeploymentException(cookbook=cookbook)
     return msg
Esempio n. 8
0
    def cookbook_deployment_test(self,
                                 user,
                                 cookbook,
                                 recipe='default',
                                 image='default'):
        """
        Try to process a cookbook and return results
        :param cookbook: cookbook to deploy
        :param recipe: recipe to deploy
        :param image: image to deploy to
        :return: dictionary with results
        """
        LOG.debug("Sending cookbook to docker server at %s" % self.dc._url)
        b_success = True
        msg = {}
        self.dc.run_container(image)
        # inject custom solo.json/solo.rb file
        json_cont = CONF.clients_puppet.cmd_config % (cookbook, recipe)
        cmd_inject = CONF.clients_puppet.cmd_inject.format(json_cont)
        self.dc.execute_command(cmd_inject)

        msg['install'] = self.run_install(cookbook)
        b_success &= msg['install']['success']
        msg['test'] = self.run_test(cookbook)
        b_success &= msg['test']['success']
        msg['deploy'] = self.run_deploy(cookbook)
        b_success &= msg['deploy']['success']

        # check execution output
        if b_success:
            msg['result'] = {
                'success': True,
                'result': "Cookbook %s successfully deployed\n" % cookbook
            }
        else:
            msg['result'] = {
                'success': False,
                'result': "Error deploying cookbook {}\n".format(cookbook)
            }
            LOG.error(_LW(msg))
        self.dc.remove_container()
        return msg
Esempio n. 9
0
 def run_install(self, user, blueprint, image):
     """Run download and install command
     :param blueprint: blueprint to process
     :return msg: operation result
     """
     try:
         self.dc.container = self.dc.run_container(image)
         cmd_install = CONF.clients_murano.cmd_install.format(blueprint)
         resp_install = self.dc.execute_command(cmd_install)
         msg = {
             'success': True,
             'response': resp_install
         }
         for line in resp_install.splitlines():
             if "ERROR" in line:
                 msg['success'] = False
         LOG.debug(_("Install result: %s") % resp_install)
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Murano install exception: %s" % e))
         raise CookbookInstallException(blueprint=blueprint)
     return msg
Esempio n. 10
0
 def run_test(self, user, blueprint, image):
     """ Test blueprint syntax
     :param blueprint: blueprint to test
     :return msg: dictionary with results and state
     """
     try:
         self.dc.container = self.dc.run_container(image)
         cmd_syntax = CONF.clients_murano.cmd_syntax.format(blueprint)
         resp_test = self.dc.execute_command(cmd_syntax)
         msg = {
             'success': True,
             'response': resp_test
         }
         for line in resp_test.splitlines():
             if "ERROR" in line:
                 msg['success'] = False
         LOG.debug(_("Test result: %s") % resp_test)
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Blueprint syntax exception %s" % e))
         raise CookbookSyntaxException(blueprint=blueprint)
     return msg
Esempio n. 11
0
 def run_deploy(self, user, blueprint, spec, image):
     """ Run blueprint deployment
     :param blueprint: blueprint to deploy
     :return msg: dictionary with results and state
     """
     try:
         # launch execution
         self.dc.container = self.dc.run_container(image)
         cmd_deploy = CONF.clients_murano.cmd_deploy
         resp_launch = self.dc.execute_command(cmd_deploy)
         msg = {
             'success': True,
             'response': resp_launch
         }
         LOG.debug(_("Launch result: %s") % resp_launch)
         if resp_launch is None or "FATAL" in resp_launch:
             msg['success'] = False
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Blueprint deployment exception %s" % e))
         raise CookbookDeploymentException(blueprint=blueprint)
     return msg
Esempio n. 12
0
 def run_deploy(self, user, cookbook, recipe, image):
     """ Run cookbook deployment
     :param cookbook: cookbook to deploy
     :return msg: dictionary with results and state
     """
     try:
         # launch execution
         self.dc.container = self.dc.run_container(image)
         cmd_deploy = CONF.clients_puppet.cmd_deploy
         resp_launch = self.dc.execute_command(cmd_deploy)
         msg = {
             'success': True,
             'response': resp_launch
         }
         LOG.debug(_("Launch result: %s") % resp_launch)
         if resp_launch is None or "FATAL" in resp_launch:
             msg['success'] = False
     except Exception as e:
         self.dc.remove_container(self.container)
         LOG.error(_LW("Cookbook deployment exception %s" % e))
         raise CookbookDeploymentException(cookbook=cookbook)
     return msg
Esempio n. 13
0
    def cookbook_deployment_test(self, user, cookbook, recipe='default', image='default'):
        """
        Try to process a cookbook and return results
        :param cookbook: cookbook to deploy
        :param recipe: recipe to deploy
        :param image: image to deploy to
        :return: dictionary with results
        """
        LOG.debug("Sending cookbook to docker server at %s" % self.dc._url)
        b_success = True
        msg = {}
        self.dc.run_container(image)
        # inject custom solo.json/solo.rb file
        json_cont = CONF.clients_puppet.cmd_config % (cookbook, recipe)
        cmd_inject = CONF.clients_puppet.cmd_inject.format(json_cont)
        self.dc.execute_command(cmd_inject)

        msg['install'] = self.run_install(cookbook)
        b_success &= msg['install']['success']
        msg['test'] = self.run_test(cookbook)
        b_success &= msg['test']['success']
        msg['deploy'] = self.run_deploy(cookbook)
        b_success &= msg['deploy']['success']

        # check execution output
        if b_success:
            msg['result'] = {
                'success': True,
                'result': "Cookbook %s successfully deployed\n" % cookbook
            }
        else:
            msg['result'] = {
                'success': False,
                'result': "Error deploying cookbook {}\n".format(cookbook)
            }
            LOG.error(_LW(msg))
        self.dc.remove_container()
        return msg
Esempio n. 14
0
    def blueprint_deployment_test(self,
                                  user,
                                  blueprint,
                                  spec='default',
                                  image='default'):
        """
        Try to process a blueprint and return results
        :param blueprint: blueprint to deploy
        :param spec: spec to deploy
        :param image: image to deploy to
        :return: dictionary with results
        """
        LOG.debug("Sending blueprint to docker server at %s" % self.dc._url)
        b_success = True
        msg = {}
        self.dc.run_container(image)
        msg['install'] = self.run_install(blueprint)
        b_success &= msg['install']['success']
        msg['test'] = self.run_test(blueprint)
        b_success &= msg['test']['success']
        msg['deploy'] = self.run_deploy(blueprint)
        b_success &= msg['deploy']['success']

        # check execution output
        if b_success:
            msg['result'] = {
                'success': True,
                'result': "Blueprint %s successfully deployed\n" % blueprint
            }
        else:
            msg['result'] = {
                'success': False,
                'result': "Error deploying blueprint {}\n".format(blueprint)
            }
            LOG.error(_LW(msg))
        self.dc.remove_container()
        return msg