Exemple #1
0
def main():
    try:
        # prepare the working environment
        args = prepare()

        # load PMT/BMT table
        xmt_mgr = xmt.XmtManager()
        xmt_mgr.load(xmt.XMT_TYPE_PMT, args.pmt)

        hostname = socket.gethostname()
        pmt_entry = xmt_mgr.get_entry(xmt.XMT_TYPE_PMT, hostname)
        log.debug("Get the PMT entry: %s", pmt_entry)

        # modify puppet config with proper environment value
        cmd = "sed -i \'s/environment=production$/environment=" + \
              pmt_entry['environment'] + "/g\' /etc/puppet/puppet.conf"
        utils.run_command(cmd)

        # start deployment with the specified build
        pbt = load_yaml(args.pbt)
        deploy_build(args, pmt_entry, pbt)

    except Exception as e:
        log.error("Error happens during post boot: %s", e)
        raise

    return 0
Exemple #2
0
def main():
    try:
        # prepare the working environment
        args = prepare()

        # load PMT/BMT table
        xmt_mgr = xmt.XmtManager()
        xmt_mgr.load(xmt.XMT_TYPE_PMT, args.pmt)

        hostname = socket.gethostname()
        pmt_entry = xmt_mgr.get_entry(xmt.XMT_TYPE_PMT, hostname)
        log.debug("Get the PMT entry: %s", pmt_entry)

        # modify puppet config with proper environment value
        cmd = "sed -i \'s/environment=production$/environment=" + \
              pmt_entry['environment'] + "/g\' /etc/puppet/puppet.conf"
        utils.run_command(cmd)

        # start deployment with the specified build
        pbt = load_yaml(args.pbt)
        deploy_build(args, pmt_entry, pbt)

    except Exception as e:
        log.error("Error happens during post boot: %s", e)
        raise

    return 0
Exemple #3
0
def run_command(cmd):
  """
  This method execute the command in another shell process in blocking mode

  raise exception if the command exits with failure
  """
  output = None
  log.debug("Executing command [%s]", cmd)
  try:
    output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
  except subprocess.CalledProcessError as ex:
    errmsg = "<errorcode>: %d \n<output>: %s\n" % (ex.returncode, ex.output)
    log.error("Executing command [%s] failed: %s", cmd, errmsg)
    raise exp.CommandFailure(cmd=cmd, error=errmsg)

  return output
  def run(self):
    """This method is the main loop for deployment
      state machine
    """
    log.info(">== deployment workflow starts.")

    deploy_state = self.current_context['state']
    log.debug("deploy_state: %s", deploy_state)
    try:
      while deploy_state != STATE_EXIT:
        action = DeployWorkflow.deploy_state_machine[deploy_state]
        action(self)
        deploy_state = self.current_context['state']
      # go through "exit" state to complete the state machine
      DeployWorkflow.deploy_state_machine[deploy_state](self)
    except Exception:
      # rollback to the beginning state
      utils.run_command_silient("git reset --hard deploy_start")
    finally:
      utils.run_command_silient("git tag -d deploy_start")
      utils.run_command_silient("git checkout master")

    log.info("<== deployment workflow completed.")