[PATCH V3 0/3] config version API support

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> V2 -> V3 add a variable in config.py.in to tell kimchi run in package directory. V1 -> V2: use rpm and dpkg to probe that kimchi run in package directory. ShaoHe Feng (3): add a method to tell the kimchi is in package directory config version API support: add a method to get kimchi version config version API support in backend. Makefile.am | 3 ++- docs/API.md | 1 + src/kimchi/Makefile.am | 11 ++++++++++- src/kimchi/config.py.in | 10 ++++++++++ src/kimchi/mockmodel.py | 3 ++- src/kimchi/model/config.py | 5 +++-- 6 files changed, 28 insertions(+), 5 deletions(-) -- 1.8.5.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> It means the kimchi run in package install path when the __inpackage__ is "yes". Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- Makefile.am | 3 ++- src/kimchi/Makefile.am | 7 +++++++ src/kimchi/config.py.in | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 6831b5d..c6935ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -102,6 +102,7 @@ all-local: install-deb: install cp -R $(top_srcdir)/contrib/DEBIAN $(DESTDIR)/ $(MKDIR_P) $(DESTDIR)/etc/init + $(MKDIR_P) $(DESTDIR)/InPackage $(MKDIR_P) $(DESTDIR)/usr/lib/firewalld/services cp -R $(top_srcdir)/contrib/kimchid-upstart.conf.debian \ $(DESTDIR)/etc/init/kimchid.conf @@ -123,7 +124,7 @@ kimchi.spec: contrib/kimchi.spec.fedora contrib/kimchi.spec.suse fi rpm: dist kimchi.spec - $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS + $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS rpm/BUILD/InPackage cp $(top_srcdir)/kimchi.spec rpm/SPECS/kimchi.spec cp $(DIST_ARCHIVES) rpm/SOURCES rpmbuild -ba --define "_topdir `pwd`/rpm" rpm/SPECS/kimchi.spec diff --git a/src/kimchi/Makefile.am b/src/kimchi/Makefile.am index 957d2c9..e48a6d1 100644 --- a/src/kimchi/Makefile.am +++ b/src/kimchi/Makefile.am @@ -43,9 +43,16 @@ do_substitution = \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ -e 's,[@]kimchidir[@],$(kimchidir),g' +inpackage_substitution = sed -i -e 's,[@]inpackage[@],yes,g' config.py: config.py.in Makefile $(do_substitution) < $(srcdir)/config.py.in > config.py + if test -d $$PWD/../../../InPackage; then \ + $(inpackage_substitution) config.py; \ + fi + if test -d $$PWD/../../../../BUILD/InPackage; then \ + $(inpackage_substitution) config.py; \ + fi BUILT_SOURCES = config.py CLEANFILES = config.py diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 04218c2..3e84215 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -29,6 +29,7 @@ from ConfigParser import SafeConfigParser from kimchi.xmlutils import xpath_get_text +__inpackage__ = "@inpackage@" DEFAULT_LOG_LEVEL = "debug" -- 1.8.5.3

I applied the whole patch set and made some tests and I think this specific patch is not needed. In fact, based on the following 2 patches we don't need to differ if the package is installed or not. With kimchi package installed or not the config.py will have: __version__ = "1.2.0" __release__ = "46.git7c3bb7b" So we can use those information to display on UI On 04/14/2014 12:38 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
It means the kimchi run in package install path when the __inpackage__ is "yes".
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- Makefile.am | 3 ++- src/kimchi/Makefile.am | 7 +++++++ src/kimchi/config.py.in | 1 + 3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am index 6831b5d..c6935ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -102,6 +102,7 @@ all-local: install-deb: install cp -R $(top_srcdir)/contrib/DEBIAN $(DESTDIR)/ $(MKDIR_P) $(DESTDIR)/etc/init + $(MKDIR_P) $(DESTDIR)/InPackage $(MKDIR_P) $(DESTDIR)/usr/lib/firewalld/services cp -R $(top_srcdir)/contrib/kimchid-upstart.conf.debian \ $(DESTDIR)/etc/init/kimchid.conf @@ -123,7 +124,7 @@ kimchi.spec: contrib/kimchi.spec.fedora contrib/kimchi.spec.suse fi
rpm: dist kimchi.spec - $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS + $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS rpm/BUILD/InPackage cp $(top_srcdir)/kimchi.spec rpm/SPECS/kimchi.spec cp $(DIST_ARCHIVES) rpm/SOURCES rpmbuild -ba --define "_topdir `pwd`/rpm" rpm/SPECS/kimchi.spec diff --git a/src/kimchi/Makefile.am b/src/kimchi/Makefile.am index 957d2c9..e48a6d1 100644 --- a/src/kimchi/Makefile.am +++ b/src/kimchi/Makefile.am @@ -43,9 +43,16 @@ do_substitution = \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ -e 's,[@]kimchidir[@],$(kimchidir),g'
+inpackage_substitution = sed -i -e 's,[@]inpackage[@],yes,g'
config.py: config.py.in Makefile $(do_substitution) < $(srcdir)/config.py.in > config.py + if test -d $$PWD/../../../InPackage; then \ + $(inpackage_substitution) config.py; \ + fi + if test -d $$PWD/../../../../BUILD/InPackage; then \ + $(inpackage_substitution) config.py; \ + fi
BUILT_SOURCES = config.py CLEANFILES = config.py diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 04218c2..3e84215 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -29,6 +29,7 @@ from ConfigParser import SafeConfigParser
from kimchi.xmlutils import xpath_get_text
+__inpackage__ = "@inpackage@"
DEFAULT_LOG_LEVEL = "debug"

On 04/15/2014 03:57 AM, Aline Manera wrote:
I applied the whole patch set and made some tests and I think this specific patch is not needed.
In fact, based on the following 2 patches we don't need to differ if the package is installed or not.
That's great. It take me a long time to think out different methods to differ if the package is installed or not. None satisfies me. And this is the better than the former two patches. Will just leave the following 2 patches next version.
With kimchi package installed or not the config.py will have:
__version__ = "1.2.0" __release__ = "46.git7c3bb7b"
So we can use those information to display on UI
On 04/14/2014 12:38 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
It means the kimchi run in package install path when the __inpackage__ is "yes".
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- Makefile.am | 3 ++- src/kimchi/Makefile.am | 7 +++++++ src/kimchi/config.py.in | 1 + 3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am index 6831b5d..c6935ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -102,6 +102,7 @@ all-local: install-deb: install cp -R $(top_srcdir)/contrib/DEBIAN $(DESTDIR)/ $(MKDIR_P) $(DESTDIR)/etc/init + $(MKDIR_P) $(DESTDIR)/InPackage $(MKDIR_P) $(DESTDIR)/usr/lib/firewalld/services cp -R $(top_srcdir)/contrib/kimchid-upstart.conf.debian \ $(DESTDIR)/etc/init/kimchid.conf @@ -123,7 +124,7 @@ kimchi.spec: contrib/kimchi.spec.fedora contrib/kimchi.spec.suse fi
rpm: dist kimchi.spec - $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS + $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS rpm/BUILD/InPackage cp $(top_srcdir)/kimchi.spec rpm/SPECS/kimchi.spec cp $(DIST_ARCHIVES) rpm/SOURCES rpmbuild -ba --define "_topdir `pwd`/rpm" rpm/SPECS/kimchi.spec diff --git a/src/kimchi/Makefile.am b/src/kimchi/Makefile.am index 957d2c9..e48a6d1 100644 --- a/src/kimchi/Makefile.am +++ b/src/kimchi/Makefile.am @@ -43,9 +43,16 @@ do_substitution = \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ -e 's,[@]kimchidir[@],$(kimchidir),g'
+inpackage_substitution = sed -i -e 's,[@]inpackage[@],yes,g'
config.py: config.py.in Makefile $(do_substitution) < $(srcdir)/config.py.in > config.py + if test -d $$PWD/../../../InPackage; then \ + $(inpackage_substitution) config.py; \ + fi + if test -d $$PWD/../../../../BUILD/InPackage; then \ + $(inpackage_substitution) config.py; \ + fi
BUILT_SOURCES = config.py CLEANFILES = config.py diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 04218c2..3e84215 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -29,6 +29,7 @@ from ConfigParser import SafeConfigParser
from kimchi.xmlutils import xpath_get_text
+__inpackage__ = "@inpackage@"
DEFAULT_LOG_LEVEL = "debug"
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> add a method to get kimchi version in config.py If kimchi run after package install, just get the version. Or get the build nubmer. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/Makefile.am | 4 +++- src/kimchi/config.py.in | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/kimchi/Makefile.am b/src/kimchi/Makefile.am index e48a6d1..90d931d 100644 --- a/src/kimchi/Makefile.am +++ b/src/kimchi/Makefile.am @@ -41,7 +41,9 @@ do_substitution = \ -e 's,[@]sysconfdir[@],$(sysconfdir),g' \ -e 's,[@]localstatedir[@],$(localstatedir),g' \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ - -e 's,[@]kimchidir[@],$(kimchidir),g' + -e 's,[@]kimchidir[@],$(kimchidir),g' \ + -e 's,[@]kimchiversion[@],$(PACKAGE_VERSION),g' \ + -e 's,[@]kimchirelease[@],$(PACKAGE_RELEASE),g' inpackage_substitution = sed -i -e 's,[@]inpackage[@],yes,g' diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 3e84215..8f2fc4e 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -30,6 +30,8 @@ from ConfigParser import SafeConfigParser from kimchi.xmlutils import xpath_get_text __inpackage__ = "@inpackage@" +__version__ = "@kimchiversion@" +__release__ = "@kimchirelease@" DEFAULT_LOG_LEVEL = "debug" @@ -55,6 +57,13 @@ def get_debugreports_path(): return os.path.join(paths.state_dir, 'debugreports') +def get_version(): + if __inpackage__ == "yes": + return __version__ + + return "-".join([__version__, __release__]) + + def find_qemu_binary(find_emulator=False): try: connect = libvirt.open('qemu:///system') -- 1.8.5.3

On 04/14/2014 12:38 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
add a method to get kimchi version in config.py
If kimchi run after package install, just get the version. Or get the build nubmer.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/Makefile.am | 4 +++- src/kimchi/config.py.in | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/kimchi/Makefile.am b/src/kimchi/Makefile.am index e48a6d1..90d931d 100644 --- a/src/kimchi/Makefile.am +++ b/src/kimchi/Makefile.am @@ -41,7 +41,9 @@ do_substitution = \ -e 's,[@]sysconfdir[@],$(sysconfdir),g' \ -e 's,[@]localstatedir[@],$(localstatedir),g' \ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ - -e 's,[@]kimchidir[@],$(kimchidir),g' + -e 's,[@]kimchidir[@],$(kimchidir),g' \ + -e 's,[@]kimchiversion[@],$(PACKAGE_VERSION),g' \ + -e 's,[@]kimchirelease[@],$(PACKAGE_RELEASE),g'
inpackage_substitution = sed -i -e 's,[@]inpackage[@],yes,g'
diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 3e84215..8f2fc4e 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -30,6 +30,8 @@ from ConfigParser import SafeConfigParser from kimchi.xmlutils import xpath_get_text
__inpackage__ = "@inpackage@" +__version__ = "@kimchiversion@" +__release__ = "@kimchirelease@"
DEFAULT_LOG_LEVEL = "debug"
@@ -55,6 +57,13 @@ def get_debugreports_path(): return os.path.join(paths.state_dir, 'debugreports')
+def get_version(): + if __inpackage__ == "yes": + return __version__ + + return "-".join([__version__, __release__]) + +
As I commented in the previous patch we don't need the "__inpackage__" we can always return "-".join([__version__, __release__])
def find_qemu_binary(find_emulator=False): try: connect = libvirt.open('qemu:///system')

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> update API.md, mockmodel, model and API.md Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/mockmodel.py | 3 ++- src/kimchi/model/config.py | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/API.md b/docs/API.md index 489f062..6da5822 100644 --- a/docs/API.md +++ b/docs/API.md @@ -560,6 +560,7 @@ Contains information about the application environment and configuration. * **GET**: Retrieve configuration information * http_port: The port number on which the server is listening * display_proxy_port: Port for vnc and spice's websocket proxy to listen on + * version: The version of the kimchi service * **POST**: *See Configuration Actions* **Actions (POST):** diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index 69eee3c..5ee4c16 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -835,7 +835,8 @@ class MockModel(object): def config_lookup(self, name): return {'http_port': cherrypy.server.socket_port, 'display_proxy_port': - kconfig.get('display', 'display_proxy_port')} + kconfig.get('display', 'display_proxy_port'), + 'version': config.get_version()} def packagesupdate_get_list(self): return self._mock_swupdate.getUpdates() diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py index a6d00ab..7081373 100644 --- a/src/kimchi/model/config.py +++ b/src/kimchi/model/config.py @@ -23,7 +23,7 @@ import cherrypy from kimchi.basemodel import Singleton from kimchi.config import config as kconfig -from kimchi.config import find_qemu_binary +from kimchi.config import find_qemu_binary, get_version from kimchi.distroloader import DistroLoader from kimchi.exception import NotFoundError from kimchi.featuretests import FeatureTests @@ -41,7 +41,8 @@ class ConfigModel(object): def lookup(self, name): proxy_port = kconfig.get('display', 'display_proxy_port') return {'http_port': cherrypy.server.socket_port, - 'display_proxy_port': proxy_port} + 'display_proxy_port': proxy_port, + 'version': get_version()} class CapabilitiesModel(object): -- 1.8.5.3

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 04/14/2014 12:38 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
update API.md, mockmodel, model and API.md
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi/mockmodel.py | 3 ++- src/kimchi/model/config.py | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/docs/API.md b/docs/API.md index 489f062..6da5822 100644 --- a/docs/API.md +++ b/docs/API.md @@ -560,6 +560,7 @@ Contains information about the application environment and configuration. * **GET**: Retrieve configuration information * http_port: The port number on which the server is listening * display_proxy_port: Port for vnc and spice's websocket proxy to listen on + * version: The version of the kimchi service * **POST**: *See Configuration Actions*
**Actions (POST):** diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index 69eee3c..5ee4c16 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -835,7 +835,8 @@ class MockModel(object): def config_lookup(self, name): return {'http_port': cherrypy.server.socket_port, 'display_proxy_port': - kconfig.get('display', 'display_proxy_port')} + kconfig.get('display', 'display_proxy_port'), + 'version': config.get_version()}
def packagesupdate_get_list(self): return self._mock_swupdate.getUpdates() diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py index a6d00ab..7081373 100644 --- a/src/kimchi/model/config.py +++ b/src/kimchi/model/config.py @@ -23,7 +23,7 @@ import cherrypy
from kimchi.basemodel import Singleton from kimchi.config import config as kconfig -from kimchi.config import find_qemu_binary +from kimchi.config import find_qemu_binary, get_version from kimchi.distroloader import DistroLoader from kimchi.exception import NotFoundError from kimchi.featuretests import FeatureTests @@ -41,7 +41,8 @@ class ConfigModel(object): def lookup(self, name): proxy_port = kconfig.get('display', 'display_proxy_port') return {'http_port': cherrypy.server.socket_port, - 'display_proxy_port': proxy_port} + 'display_proxy_port': proxy_port, + 'version': get_version()}
class CapabilitiesModel(object):
participants (3)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com
-
Sheldon