Skip to content

Commit

Permalink
Provide DBus objects for configuration, facts, and registration.
Browse files Browse the repository at this point in the history
This commit creates DBus objects off the com.redhat.RHSM1 namespace.
Objects include Facts which is meant to gather all the relevant system
facts, Config which gives access to the subscription-manager
configuration settings, and RegisterServer which opens a domain socket
with another DBus object listening to allow for system registration.
The indirection over the domain socket is so that credentials will be
passed securely from one process to another instead of going over the
system bus.

This commit also retrofits the main subscription-manager code to use the
Facts and Config objects.
  • Loading branch information
awood committed Jan 6, 2017
1 parent 0637c6a commit 2aa48ef
Show file tree
Hide file tree
Showing 123 changed files with 5,884 additions and 780 deletions.
71 changes: 55 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
# just the fastest or easiest way.

SHELL := /bin/bash
PREFIX ?=
PREFIX ?= /
SYSCONF ?= etc
INSTALL_DIR = usr/share

PYTHON_SITELIB ?= usr/lib/python2.7/site-packages
# Note the underscore used instead of a hyphen
PYTHON_INST_DIR = $(PREFIX)/$(PYTHON_SITELIB)/subscription_manager

OS = $(shell lsb_release -i | awk '{ print $$3 }' | awk -F. '{ print $$1}')
OS_VERSION = $(shell lsb_release -r | awk '{ print $$2 }' | awk -F. '{ print $$1}')
OS_DIST ?= $(shell rpm --eval='%dist')

PYTHON_VER ?= $(python -c 'import sys; print("python%s.%s" % sys.version_info[:2])')

PYTHON_SITELIB ?= usr/lib/$(PYTHON_VER)/site-packages
# Note the underscore used instead of a hyphen
PYTHON_INST_DIR = $(PREFIX)/$(PYTHON_SITELIB)/subscription_manager

# Where various bits of code live in the git repo
SRC_DIR := src/subscription_manager
RCT_SRC_DIR := src/rct
Expand All @@ -41,6 +43,7 @@ RHSM_PLUGIN_DIR := $(PREFIX)/usr/share/rhsm-plugins/
RHSM_PLUGIN_CONF_DIR := $(PREFIX)/etc/rhsm/pluginconf.d/
ANACONDA_ADDON_INST_DIR := $(PREFIX)/usr/share/anaconda/addons
INITIAL_SETUP_INST_DIR := $(ANACONDA_ADDON_INST_DIR)/$(ANACONDA_ADDON_NAME)
POLKIT_ACTIONS_INST_DIR := $(PREFIX)/$(INSTALL_DIR)/polkit-1/actions
LIBEXEC_DIR ?= $(shell rpm --eval='%_libexecdir')

# If we skip install ostree plugin, unset by default
Expand All @@ -53,6 +56,7 @@ ifeq ($(OS_DIST),.el6)
FIRSTBOOT_MODULES_DIR?=$(PREFIX)/usr/share/rhn/up2date_client/firstboot
INSTALL_FIRSTBOOT?=true
INSTALL_INITIAL_SETUP?=false
DBUS_SERVICE_FILE_TYPE?=dbus
else ifeq ($(OS),SUSE)
GTK_VERSION?=2
FIRSTBOOT_MODULES_DIR?=$(PREFIX)/usr/share/rhn/up2date_client/firstboot
Expand All @@ -63,6 +67,21 @@ else
FIRSTBOOT_MODULES_DIR?=$(PREFIX)/usr/share/firstboot/modules
INSTALL_FIRSTBOOT?=true
INSTALL_INITIAL_SETUP?=true
DBUS_SERVICE_FILE_TYPE?=systemd
endif

DBUS_SERVICES_CONF_INST_DIR := $(PREFIX)/usr/share/dbus-1/system-services
FACTS_INST_DBUS_SERVICE_FILE = $(DBUS_SERVICES_CONF_INST_DIR)/com.redhat.RHSM1.Facts.service
MAIN_INST_DBUS_SERVICE_FILE = $(DBUS_SERVICES_CONF_INST_DIR)/com.redhat.RHSM1.service
# TODO Ideally these service files would be installed by distutils, but the file we actually
# install depends on the distro we are using. Add a --without-systemd or similar flag to the
# custom install_data class we have in setup.py
ifeq ($(DBUS_SERVICE_FILE_TYPE),dbus)
FACTS_SRC_DBUS_SERVICE_FILE = etc-conf/dbus/com.redhat.RHSM1.Facts.service-dbus
MAIN_SRC_DBUS_SERVICE_FILE = etc-conf/dbus/com.redhat.RHSM1.service-dbus
else
FACTS_SRC_DBUS_SERVICE_FILE = etc-conf/dbus/com.redhat.RHSM1.Facts.service
MAIN_SRC_DBUS_SERVICE_FILE = etc-conf/dbus/com.redhat.RHSM1.service
endif

# always true until fedora is just dnf
Expand Down Expand Up @@ -119,17 +138,36 @@ rhsm-icon: $(RHSM_ICON_SRC_DIR)/rhsm_icon.c
check-syntax:
$(CC) -fsyntax-only $(CFLAGS) $(LDFLAGS) $(ICON_FLAGS) `find -name '*.c'`

.PHONY: dbus-service-install
dbus-service-install:
dbus-common-install:
install -d $(PREFIX)/etc/dbus-1/system.d
if [ "$(DBUS_SERVICE_FILE_TYPE)" == "systemd" ]; then \
install -d $(SYSTEMD_INST_DIR) ; \
fi
install -d $(PREFIX)/$(INSTALL_DIR)/dbus-1/system-services
install -d $(PREFIX)/$(LIBEXEC_DIR)
install -m 644 etc-conf/com.redhat.SubscriptionManager.conf \
$(PREFIX)/etc/dbus-1/system.d
install -m 644 etc-conf/com.redhat.SubscriptionManager.service \
$(PREFIX)/$(INSTALL_DIR)/dbus-1/system-services
install -m 744 $(DAEMONS_SRC_DIR)/rhsm_d.py \
$(PREFIX)/$(LIBEXEC_DIR)/rhsmd
install -d $(PREFIX)/etc/bash_completion.d

dbus-rhsmd-service-install: dbus-common-install
install -m 644 etc-conf/dbus/com.redhat.SubscriptionManager.conf $(PREFIX)/etc/dbus-1/system.d
install -m 644 etc-conf/dbus/com.redhat.SubscriptionManager.service $(PREFIX)/$(INSTALL_DIR)/dbus-1/system-services
install -m 744 $(DAEMONS_SRC_DIR)/rhsm_d.py $(PREFIX)/$(LIBEXEC_DIR)/rhsmd

dbus-facts-service-install: dbus-common-install
install -m 644 etc-conf/dbus/com.redhat.RHSM1.Facts.conf $(PREFIX)/etc/dbus-1/system.d
if [ "$(DBUS_SERVICE_FILE_TYPE)" == "systemd" ]; then \
install -m 644 etc-conf/dbus/rhsm-facts.service $(SYSTEMD_INST_DIR) ; \
fi
install -m 644 $(FACTS_SRC_DBUS_SERVICE_FILE) $(FACTS_INST_DBUS_SERVICE_FILE)

dbus-main-service-install: dbus-common-install
install -m 644 etc-conf/dbus/com.redhat.RHSM1.conf $(PREFIX)/etc/dbus-1/system.d
if [ "$(DBUS_SERVICE_FILE_TYPE)" == "systemd" ]; then \
install -m 644 etc-conf/dbus/rhsm.service $(SYSTEMD_INST_DIR) ; \
fi
install -m 644 $(MAIN_SRC_DBUS_SERVICE_FILE) $(MAIN_INST_DBUS_SERVICE_FILE)

.PHONY: dbus-install
dbus-install: dbus-facts-service-install dbus-rhsmd-service-install dbus-main-service-install

.PHONY: install-conf
install-conf:
Expand All @@ -150,6 +188,9 @@ install-conf:
install -m 644 etc-conf/rhsmcertd.completion.sh $(PREFIX)/etc/bash_completion.d/rhsmcertd
install -d $(PREFIX)/usr/share/appdata
install -m 644 etc-conf/subscription-manager-gui.appdata.xml $(PREFIX)/$(INSTALL_DIR)/appdata/subscription-manager-gui.appdata.xml
install -d $(POLKIT_ACTIONS_INST_DIR)
install -m 644 etc-conf/dbus/com.redhat.RHSM1.policy $(POLKIT_ACTIONS_INST_DIR)
install -m 644 etc-conf/dbus/com.redhat.RHSM1.Facts.policy $(POLKIT_ACTIONS_INST_DIR)

.PHONY: install-plugins
install-plugins:
Expand Down Expand Up @@ -251,7 +292,7 @@ install-via-setup:
install: install-via-setup install-files

.PHONY: install-files
install-files: dbus-service-install install-conf install-plugins install-post-boot install-ga
install-files: dbus-install install-conf install-plugins install-post-boot install-ga
install -d $(PREFIX)/var/log/rhsm
install -d $(PREFIX)/var/spool/rhsm/debug
install -d $(PREFIX)/var/run/rhsm
Expand All @@ -260,7 +301,6 @@ install-files: dbus-service-install install-conf install-plugins install-post-bo
# Set up rhsmcertd daemon. If installing on Fedora or RHEL 7+
# we prefer systemd over sysv as this is the new trend.
if [ $(OS) = Fedora ] ; then \
install -d $(SYSTEMD_INST_DIR); \
install -d $(PREFIX)/usr/lib/tmpfiles.d; \
install etc-conf/rhsmcertd.service $(SYSTEMD_INST_DIR); \
install etc-conf/subscription-manager.conf.tmpfiles \
Expand All @@ -281,7 +321,6 @@ install-files: dbus-service-install install-conf install-plugins install-post-bo
install etc-conf/rhsmcertd.init.d \
$(PREFIX)/etc/rc.d/init.d/rhsmcertd; \
else \
install -d $(SYSTEMD_INST_DIR); \
install -d $(PREFIX)/usr/lib/tmpfiles.d; \
install etc-conf/rhsmcertd.service $(SYSTEMD_INST_DIR); \
install etc-conf/subscription-manager.conf.tmpfiles \
Expand Down
43 changes: 43 additions & 0 deletions bin/rhsm-facts-service
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! /usr/bin/env python
#
# Copyright (c) 2016 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
import logging

# Init logging very early so we can log any issues that occur at import time
logging.basicConfig(level=logging.DEBUG, format="%(levelname)5s [%(name)s:%(lineno)s] %(message)s")
log = logging.getLogger('')
log.setLevel(logging.INFO)

import sys
from rhsmlib.dbus import service_wrapper
from rhsmlib.dbus.facts import base, constants

if __name__ == "__main__":
try:
object_classes = [
base.AllFacts,
]
sys.exit(service_wrapper.main(
sys.argv,
object_classes=object_classes,
default_bus_name=constants.FACTS_DBUS_NAME)
)
except Exception:
log.exception("DBus service startup failed")
else:
# Importing this module would screw up the importer's logging configuration since
# we're setting up logging very early in module scope to catch any log messages that
# occur during the loading of the dependent modules.
raise ImportError("This module is not meant to be imported")
41 changes: 41 additions & 0 deletions bin/rhsm-service
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python
#
# Copyright (c) 2016 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#
import logging

# Init logging very early so we can log any issues that occur at import time
logging.basicConfig(level=logging.DEBUG, format="%(levelname)5s [%(name)s:%(lineno)s] %(message)s")
log = logging.getLogger('')
log.setLevel(logging.INFO)

import sys
from rhsmlib.dbus import service_wrapper
from rhsmlib.dbus import objects

if __name__ == "__main__":
try:
object_classes = [
objects.ConfigDBusObject,
objects.RegisterDBusObject,
objects.Main
]
sys.exit(service_wrapper.main(sys.argv, object_classes=object_classes))
except Exception:
log.exception("DBus service startup failed")
else:
# Importing this module would screw up the importer's logging configuration since
# we're setting up logging very early in module scope to catch any log messages that
# occur during the loading of the dependent modules.
raise ImportError("This module is not meant to be imported")
4 changes: 4 additions & 0 deletions bin/subscription-manager
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ try:
from subscription_manager.injectioninit import init_dep_injection
init_dep_injection()

import subscription_manager.injection as inj
# Set up DBus mainloop via DBUS_IFACE
inj.require(inj.DBUS_IFACE)

from subscription_manager import managercli
from subscription_manager.managercli import handle_exception

Expand Down
4 changes: 4 additions & 0 deletions bin/subscription-manager-gui
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ try:
from subscription_manager.injectioninit import init_dep_injection
init_dep_injection()

import subscription_manager.injection as inj
# Set up DBus mainloop via DBUS_IFACE
inj.require(inj.DBUS_IFACE)

from subscription_manager.gui import managergui
from subscription_manager.i18n_optparse import OptionParser, \
WrappedIndentedHelpFormatter, USAGE
Expand Down
108 changes: 108 additions & 0 deletions build_ext/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# in this software or its documentation.
import ast
import re
import tokenize

from distutils.spawn import spawn
from distutils.text_file import TextFile
Expand All @@ -21,6 +22,9 @@
# These dependencies aren't available in build environments. We won't need any
# linting functionality there though, so just create a dummy class so we can proceed.
try:
# These dependencies aren't available in build environments. We won't need any
# linting functionality there though, so just create a dummy class so we can proceed.
import pep8
import pkg_resources
except ImportError:
pass
Expand Down Expand Up @@ -364,6 +368,110 @@ def err(self, node, msg=None):
return ret


def detect_overindent(logical_line, tokens, indent_level, hang_closing, indent_char, noqa, verbose):
"""Flag lines that are overindented. This includes lines that are indented solely to align
vertically with an opening brace. This rule allows continuation lines to be relatively
indented up to 8 spaces and closes braces to be relatively indented up to 4 spaces. Heavily
adapted from pep8's continued_indentation method
Okay: foo = my_func('hello',
'world'
)
Okay: foo = my_func('hello',
'world')
Okay: foo = my_func('hello',
)
E198: foo = my_func('hello',
)
E199: foo = my_func('hello',
'world')
"""
first_row = tokens[0][2][0]
nrows = 1 + tokens[-1][2][0] - first_row
if noqa or nrows == 1:
return

row = depth = 0

# relative indents of physical lines
rel_indent = [0] * nrows
open_rows = [[0]]
last_indent = tokens[0][2]
indent = [last_indent[1]]

last_token_multiline = False

if verbose >= 3:
print(">>> " + tokens[0][4].rstrip())

for token_type, text, start, end, line in tokens:
newline = row < start[0] - first_row
if newline:
row = start[0] - first_row
newline = not last_token_multiline and token_type not in pep8.NEWLINE

if newline:
# this is the beginning of a continuation line.
last_indent = start
if verbose >= 3:
print("... " + line.rstrip())

# record the initial indent.
rel_indent[row] = pep8.expand_indent(line) - indent_level

# identify closing bracket
close_bracket = (token_type == tokenize.OP and text in ']})')

# is the indent relative to an opening bracket line?
for open_row in reversed(open_rows[depth]):
hang = rel_indent[row] - rel_indent[open_row]

if not close_bracket and hang > 8:
yield start, "E199 continuation line over-indented"

if close_bracket and hang > 4:
yield (start, "E198 closing bracket over-indented")

# Keep track of bracket depth to check for proper indentation in nested
# brackets
# E.g.
# Okay: foo = [[
# '1'
# ]]
#
# but even though we are nested twice, we should only allow one level of indentation, so:
#
# E199: foo = [[
# '1'
# ]]

if token_type == tokenize.OP:
if text in '([{':
depth += 1
indent.append(0)
if len(open_rows) == depth:
open_rows.append([])
open_rows[depth].append(row)
if verbose >= 4:
print("bracket depth %s seen, col %s, visual min = %s" %
(depth, start[1], indent[depth]))
elif text in ')]}' and depth > 0:
# parent indents should not be more than this one
prev_indent = indent.pop() or last_indent[1]
for d in range(depth):
if indent[d] > prev_indent:
indent[d] = 0
del open_rows[depth + 1:]
depth -= 1
assert len(indent) == depth + 1

last_token_multiline = (start[0] != end[0])
if last_token_multiline:
rel_indent[end[0] - first_row] = rel_indent[row]


class PluginLoadingFlake8(Flake8):
"""A Flake8 runner that will load our custom plugins. It's important to note
that this has to be invoked via `./setup.py flake8`. Just running `flake8` won't
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-r test-requirements.txt
yanc
nose-randomly
xtraceback
Loading

0 comments on commit 2aa48ef

Please sign in to comment.