示例#1
0
 def test_can_convert_upstart_from_string_to_bool(self):
     for val in ("y", "yes", "t", "true", "on", "1", " YES "):
         self.assertTrue(str_to_bool(val))
     for val in ("n", "no", "f", "false", "off", "0", " NO "):
         self.assertFalse(str_to_bool(val))
示例#2
0
文件: core.py 项目: dnfehren/mendel
    def __init__(
            self,
            service_name,
            service_root=None,
            build_target_path=None,
            user=None,
            group=None,
            bundle_type=None,
            project_type=None,
            cwd=None,
            jar_name=None,
            nexus_user=None,
            nexus_host=None,
            nexus_port=None,
            nexus_repository=None,
            graphite_host=None,
            api_service_name=None,
            slack_url=None,
            slack_emoji=":rocket:",
            use_upstart=True,
            **kwargs
    ):

        self._service_name = service_name
        self._service_root = service_root or os.path.join('/srv', self._service_name)
        self._build_target_path = build_target_path or 'target/%s' % self._service_name
        self._user = user or service_name
        self._group = group or user or service_name
        self._bundle_type = bundle_type or 'jar'
        self._project_type = project_type or 'java'
        self._cwd = cwd or '.'
        self._jar_name = jar_name or service_name
        self._api_service_name = api_service_name

        self._version_control = "hg" if os.path.exists(".hg") else "git"
        self._release_dir = None

        self._nexus_user = nexus_user or config.NEXUS_USER
        self._nexus_host = nexus_host or config.NEXUS_HOST
        self._nexus_port = nexus_port or config.NEXUS_PORT
        self._nexus_repository = nexus_repository or config.NEXUS_REPOSITORY

        self._graphite_host = graphite_host or config.GRAPHITE_HOST
        self._slack_url = slack_url
        self._slack_emoji = slack_emoji
        self._track_event_endpoint = config.TRACK_EVENT_ENDPOINT
        if isinstance(use_upstart, basestring):
            self._use_upstart = str_to_bool(use_upstart)
        else:
            self._use_upstart = use_upstart

        # Hack -- Who needs polymorphism anyways?
        #
        # but really, TODO make subclasses for each bundle type
        # when this supports python AND java,
        # will probably want a builder delegate and a deployer delegate
        # because cross products
        if bundle_type == 'tgz':
            self._install = self._install_tgz
            self._upload = self._upload_tgz
            self._rollback = self._symlink_rollback
        elif bundle_type == 'deb':
            self._install = self._install_deb
            self._upload = self._upload_deb
            self._rollback = self._symlink_rollback
        elif bundle_type == 'jar':
            self._install = self._install_jar
            self._upload = self._upload_jar
            self._rollback = self._symlink_rollback
        elif bundle_type == 'remote_deb':
            self._install = self._install_remote_deb
            self._upload = self._upload_remote_deb
            self._rollback = self._apt_rollback

            # this is a hack, we "build" during
            # the "upload" task via `mvn deploy`
            self._mark_as_built()
示例#3
0
    def __init__(self,
                 service_name,
                 service_root=None,
                 build_target_path=None,
                 user=None,
                 group=None,
                 bundle_type=None,
                 project_type=None,
                 cwd=None,
                 jar_name=None,
                 classifier=None,
                 nexus_user=None,
                 nexus_host=None,
                 nexus_port=None,
                 nexus_repository=None,
                 graphite_host=None,
                 api_service_name=None,
                 slack_url=None,
                 slack_emoji=":rocket:",
                 use_upstart=True,
                 use_init=True,
                 **kwargs):

        self._service_name = service_name
        self._service_root = service_root or os.path.join(
            '/srv', self._service_name)
        self._build_target_path = build_target_path or 'target/%s' % self._service_name
        self._user = user or service_name
        self._group = group or user or service_name
        self._bundle_type = bundle_type or 'remote_jar'
        self._project_type = project_type or 'java'
        self._cwd = cwd or '.'
        self._jar_name = jar_name or service_name
        # Search for a jar in nexus that uses a classifier in its name, e.g. "shaded" -> "foo-1.1.1-shaded.jar"
        self._classifier = classifier
        self._api_service_name = api_service_name

        self._version_control = "hg" if os.path.exists(".hg") else "git"
        self._release_dir = None

        self._nexus_user = nexus_user or config.NEXUS_USER
        self._nexus_host = nexus_host or config.NEXUS_HOST
        self._nexus_port = nexus_port or config.NEXUS_PORT
        self._nexus_repository = nexus_repository or config.NEXUS_REPOSITORY

        self._graphite_host = graphite_host or config.GRAPHITE_HOST
        self._deployment_user = config.DEPLOYMENT_USER or getpass.getuser()
        self._slack_url = slack_url
        self._slack_emoji = slack_emoji
        self._track_event_endpoint = config.TRACK_EVENT_ENDPOINT
        self.project_version = ''
        self._project_version_specified = False
        if isinstance(use_init, basestring):
            self._use_init = str_to_bool(use_init)
        else:
            self._use_init = use_init

        if isinstance(use_upstart, basestring):
            print red(
                "DEPRECATION WARNING: use_upstart must be changed to use_init."
            )
            self._use_init = str_to_bool(use_upstart)
        else:
            print red(
                "DEPRECATION WARNING: use_upstart must be changed to use_init."
            )
            self._use_init = use_upstart

        # Hack -- Who needs polymorphism anyways?
        #
        # but really, TODO make subclasses for each bundle type
        # when this supports python AND java,
        # will probably want a builder delegate and a deployer delegate
        # because cross products
        if bundle_type == 'tgz':
            self._install = self._install_tgz
            self._upload = self._upload_tgz
            self._rollback = self._symlink_rollback
        elif bundle_type == 'deb':
            self._install = self._install_deb
            self._upload = self._upload_deb
            self._rollback = self._symlink_rollback
        elif bundle_type == 'jar':
            self._install = self._install_jar
            self._upload = self._upload_jar
            self._rollback = self._symlink_rollback
        elif bundle_type == 'remote_jar':
            self._install = self._install_remote_jar
            self._upload = self._upload_remote_jar
            self._rollback = self._symlink_rollback
        elif bundle_type == 'remote_deb':
            self._install = self._install_remote_deb
            self._upload = self._upload_remote_deb
            self._rollback = self._apt_rollback

            # this is a hack, we "build" during
            # the "upload" task via `mvn deploy`
            self._mark_as_built()
示例#4
0
 def test_can_convert_upstart_from_string_to_bool(self):
     for val in ("y", "yes", "t", "true", "on", "1", " YES "):
         self.assertTrue(str_to_bool(val))
     for val in ("n", "no", "f", "false", "off", "0", " NO "):
         self.assertFalse(str_to_bool(val))