[lxc-devel] [lxd/master] Don't special-case mock mode unnecessarily in db patches

freeekanayaka on Github lxc-bot at linuxcontainers.org
Tue May 16 08:16:44 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1002 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170516/b4ffebd4/attachment.bin>
-------------- next part --------------
From 416e620641ef80e191056bd7465829ad7716777a Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Tue, 16 May 2017 10:12:27 +0200
Subject: [PATCH] Don't special-case mock mode unnecessarily in db patches

A few db patches are currently checking if the daemon is being run in
mock mode (i.e. unit tests), and no-op the patch in that.

It turns out that this is not really necessary, becasue the underlying
logic will work fine in mock mode too (and also, more generally it
might open the doors to creating tests that specicically exercise
certain patches).

This change removes all current occurrences of the special casing, the
main goal would be to reduce coupling between daemon
code (higher-level) and db code (lower-level), so eventually we can
have dependencies only in one direction (deamon depends on db but not
viceversa).

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 lxd/db_update.go | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/lxd/db_update.go b/lxd/db_update.go
index 6119835..3929be4 100644
--- a/lxd/db_update.go
+++ b/lxd/db_update.go
@@ -224,10 +224,6 @@ CREATE TABLE IF NOT EXISTS patches (
 }
 
 func dbUpdateFromV30(currentVersion int, version int, d *Daemon) error {
-	if d.MockMode {
-		return nil
-	}
-
 	entries, err := ioutil.ReadDir(shared.VarPath("containers"))
 	if err != nil {
 		/* If the directory didn't exist before, the user had never
@@ -267,10 +263,6 @@ func dbUpdateFromV30(currentVersion int, version int, d *Daemon) error {
 }
 
 func dbUpdateFromV29(currentVersion int, version int, d *Daemon) error {
-	if d.MockMode {
-		return nil
-	}
-
 	if shared.PathExists(shared.VarPath("zfs.img")) {
 		err := os.Chmod(shared.VarPath("zfs.img"), 0600)
 		if err != nil {
@@ -573,12 +565,6 @@ ALTER TABLE images ADD COLUMN last_use_date DATETIME;`
 }
 
 func dbUpdateFromV11(currentVersion int, version int, d *Daemon) error {
-	if d.MockMode {
-		// No need to move snapshots no mock runs,
-		// dbUpdateFromV12 will then set the db version to 13
-		return nil
-	}
-
 	cNames, err := dbContainersList(d.db, cTypeSnapshot)
 	if err != nil {
 		return err
@@ -647,12 +633,6 @@ func dbUpdateFromV11(currentVersion int, version int, d *Daemon) error {
 }
 
 func dbUpdateFromV10(currentVersion int, version int, d *Daemon) error {
-	if d.MockMode {
-		// No need to move lxc to containers in mock runs,
-		// dbUpdateFromV12 will then set the db version to 13
-		return nil
-	}
-
 	if shared.PathExists(shared.VarPath("lxc")) {
 		err := os.Rename(shared.VarPath("lxc"), shared.VarPath("containers"))
 		if err != nil {


More information about the lxc-devel mailing list