def test_check_snappy_service_poststop_absolute_path(self):
     '''Test check_snappy_service_poststop() - absolute path'''
     self._set_service([("poststop", "/foo/bar/some/poststop")])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_poststop()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_poststop_unspecified(self):
     '''Test check_snappy_service_poststop() - unspecified'''
     # self._set_service([("poststop", None)])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_poststop()
     r = c.click_report
     expected_counts = {'info': 0, 'warn': 0, 'error': 0}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_poststop_empty(self):
     '''Test check_snappy_service_poststop() - empty'''
     self._set_service([("poststop", "")])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_poststop()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_stop(self):
     '''Test check_snappy_service_stop()'''
     self._set_service([("stop", "some/stop")])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_stop()
     r = c.click_report
     expected_counts = {'info': 2, 'warn': 0, 'error': 0}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_description_unspecified(self):
     '''Test check_snappy_service_description() - unspecified'''
     # self._set_service([("description", None)])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_description()
     r = c.click_report
     # required check is done elsewhere, so no error
     expected_counts = {'info': 0, 'warn': 0, 'error': 0}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_ports(self):
     '''Test check_snappy_service_ports()'''
     ports = self._create_ports()
     self.set_test_systemd(self.default_appname, "ports", ports)
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_ports()
     r = c.click_report
     expected_counts = {'info': 8, 'warn': 0, 'error': 0}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_stop_timeout_bad_granularity(self):
     '''Test check_snappy_service_stop_timeout() - bad with granularity'''
     self._set_service([("start", "bin/foo"), ("description", "something"),
                        ("stop-timeout", "30a")])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_stop_timeout()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_stop_timeout_range_high(self):
     '''Test check_snappy_service_stop_timeout() - out of range (high)'''
     self._set_service([("start", "bin/foo"), ("description", "something"),
                        ("stop-timeout", 61)])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_stop_timeout()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_unknown(self):
     '''Test check_snappy_unknown()'''
     self.set_test_systemd(self.default_appname,
                           key="nonexistent",
                           value="foo")
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_unknown()
     r = c.click_report
     expected_counts = {'info': 0, 'warn': 1, 'error': 0}
     self.check_results(r, expected_counts)
 def test_check_snappy_optional_stop_without_start(self):
     '''Test check_snappy_optional() - with stop, no start'''
     self.set_test_systemd(self.default_appname,
                           key="stop",
                           value="/bin/bar")
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_optional()
     r = c.click_report
     expected_counts = {'info': 9, 'warn': 0, 'error': 0}
     self.check_results(r, expected_counts)
 def test_check_snappy_optional_none(self):
     '''Test check_snappy_optional() - start only'''
     self.set_test_systemd(self.default_appname,
                           key="start",
                           value="/bin/foo")
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_optional()
     r = c.click_report
     expected_counts = {'info': 9, 'warn': 0, 'error': 0}
     self.check_results(r, expected_counts)
    def test_check_snappy_service_ports_missing_external_subkey(self):
        '''Test check_snappy_service_ports() - missing external subkey'''
        ports = self._create_ports()
        del ports['external']['ext2']['port']

        self.set_test_systemd(self.default_appname, "ports", ports)
        c = ClickReviewSystemd(self.test_name)
        c.check_snappy_service_ports()
        r = c.click_report
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
        self.check_results(r, expected_counts)
 def test_check_snappy_service_socket_no_listen_stream(self):
     '''Test check_snappy_service_socket() - missing listen-stream'''
     name = self.test_name.split('_')[0]
     self.set_test_pkg_yaml("name", name)
     self._set_service([("start", "bin/test-app"),
                        ("description", "something"), ("socket", True)])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_socket()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_required_bad_value(self):
     '''Test check_snappy_required() - bad start'''
     self.set_test_systemd(self.default_appname, key="start", value=[])
     self.set_test_systemd(self.default_appname,
                           key="description",
                           value="something")
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_required()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
    def test_check_snappy_service_ports_invalid_internal_negotiable(self):
        '''Test check_snappy_service_ports() - invalid internal negotiable'''
        ports = self._create_ports()
        ports['internal']['int1']['negotiable'] = -99999999

        self.set_test_systemd(self.default_appname, "ports", ports)
        c = ClickReviewSystemd(self.test_name)
        c.check_snappy_service_ports()
        r = c.click_report
        expected_counts = {'info': None, 'warn': 0, 'error': 1}
        self.check_results(r, expected_counts)
 def test_check_snappy_optional_stop_bad(self):
     '''Test check_snappy_optional() - with bad stop'''
     self.set_test_systemd(self.default_appname,
                           key="start",
                           value="/bin/foo")
     self.set_test_systemd(self.default_appname, key="stop", value=[])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_optional()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_listen_stream_bad_abstract(self):
     '''Test check_snappy_service_listen_stream() - bad (wrong name)'''
     name = self.test_name.split('_')[0]
     self.set_test_pkg_yaml("name", name)
     self._set_service([("start", "bin/test-app"),
                        ("description", "something"),
                        ("listen-stream", '@%s/nomatch' % name)])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_listen_stream()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_bus_name_empty(self):
     '''Test check_snappy_service_bus_name() - bad (empty)'''
     name = self.test_name.split('_')[0]
     self.set_test_pkg_yaml("name", name)
     self._set_service([("start", "bin/test-app"),
                        ("description", "something"), ("bus-name", "")])
     self.set_test_pkg_yaml("type", 'framework')
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_bus_name()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_bus_name_missing_framework_oem(self):
     '''Test check_snappy_service_bus_name() - missing framework (oem)'''
     name = self.test_name.split('_')[0]
     self._set_service([("start", "bin/test-app"),
                        ("description", "something"),
                        ("bus-name", "%s.%s" % (name, "test-app"))])
     self.set_test_pkg_yaml("type", 'oem')
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_bus_name()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 1}
     self.check_results(r, expected_counts)
 def test_check_snappy_service_socket_group_bad(self):
     '''Test check_snappy_service_socket_group() - bad group'''
     name = self.test_name.split('_')[0]
     self.set_test_pkg_yaml("name", name)
     self._set_service([("start", "bin/test-app"),
                        ("description", "something"),
                        ("listen-stream", '@%s' % name),
                        ("socket-group", name + "nomatch")])
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_service_socket_group()
     r = c.click_report
     expected_counts = {'info': None, 'warn': 0, 'error': 2}
     self.check_results(r, expected_counts)
 def test_check_snappy_required(self):
     '''Test check_required() - has start and description'''
     self.set_test_systemd(self.default_appname,
                           key="start",
                           value="bin/foo")
     self.set_test_systemd(self.default_appname,
                           key="description",
                           value="something")
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_required()
     r = c.click_report
     expected_counts = {'info': 2, 'warn': 0, 'error': 0}
     self.check_results(r, expected_counts)
 def test_check_snappy_unknown_multiple(self):
     '''Test check_snappy_unknown() - multiple with nonexistent'''
     self.set_test_systemd(self.default_appname,
                           key="start",
                           value="/bin/foo")
     self.set_test_systemd(self.default_appname,
                           key="stop",
                           value="bin/bar")
     self.set_test_systemd(self.default_appname,
                           key="nonexistent",
                           value="foo")
     c = ClickReviewSystemd(self.test_name)
     c.check_snappy_unknown()
     r = c.click_report
     expected_counts = {'info': 0, 'warn': 1, 'error': 0}
     self.check_results(r, expected_counts)