summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/plugins/print_architecture_plugin.py35
-rw-r--r--morphlib/util.py22
-rw-r--r--without-test-modules1
-rw-r--r--yarns/print-architecture.yarn42
4 files changed, 100 insertions, 0 deletions
diff --git a/morphlib/plugins/print_architecture_plugin.py b/morphlib/plugins/print_architecture_plugin.py
new file mode 100644
index 00000000..08f500d0
--- /dev/null
+++ b/morphlib/plugins/print_architecture_plugin.py
@@ -0,0 +1,35 @@
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+import cliapp
+import os
+
+import morphlib
+
+
+class PrintArchitecturePlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.add_subcommand(
+ 'print-architecture', self.print_architecture, arg_synopsis='')
+
+ def disable(self):
+ pass
+
+ def print_architecture(self, args):
+ '''Print the name of the architecture of the host.'''
+
+ self.app.output.write('%s\n' % morphlib.util.get_host_architecture())
diff --git a/morphlib/util.py b/morphlib/util.py
index b83211e3..7526c93c 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -359,3 +359,25 @@ def parse_environment_pairs(env, pairs):
# 3 unnecessary lists, but I felt this was the most
# easy to read. Using itertools.chain may be more efficicent
return dict(env.items() + extra_env.items())
+
+
+
+def get_host_architecture(): # pragma: no cover
+ '''Get the canonical Morph name for the host's architecture.'''
+
+ machine = os.uname()[-1]
+
+ table = {
+ 'x86_64': 'x86_64',
+ 'i386': 'x86_32',
+ 'i486': 'x86_32',
+ 'i586': 'x86_32',
+ 'i686': 'x86_32',
+ 'armv7l': 'armv7l',
+ 'armv7b': 'armv7b',
+ }
+
+ if machine not in table:
+ raise morphlib.Error('Unknown host architecture %s' % machine)
+
+ return table[machine]
diff --git a/without-test-modules b/without-test-modules
index 9e2f39aa..861680aa 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -28,3 +28,4 @@ morphlib/plugins/copy-artifacts_plugin.py
morphlib/plugins/trovectl_plugin.py
morphlib/plugins/gc_plugin.py
morphlib/plugins/branch_and_merge_new_plugin.py
+morphlib/plugins/print_architecture_plugin.py
diff --git a/yarns/print-architecture.yarn b/yarns/print-architecture.yarn
new file mode 100644
index 00000000..e45d7d1b
--- /dev/null
+++ b/yarns/print-architecture.yarn
@@ -0,0 +1,42 @@
+"morph print-architecture" tests
+================================
+
+This is short and simple. Morph can print the name for the current
+architecture, and we verify not that it is correct, but that exactly
+one line is printed to the standard output. The reason we're not
+checking it's correct is because that would require the test code
+to duplicate the architecture name list that is in the code already,
+and that wouldn't help with tests. However, verifying there's exactly
+one line in stdout (and nothing in stderr) means the plugin does at
+least something sensible.
+
+Oh, and the one line should contain no spaces, either.
+
+ SCENARIO morph print-architecture prints out a single word
+ WHEN morph print-architecture is run
+ THEN stdout contains a single line
+ AND stdout contains no spaces
+ AND stderr is empty
+
+ IMPLEMENTS WHEN morph print-architecture is run
+ run_morph print-architecture > "$DATADIR/stdout" 2> "$DATADIR/stderr"
+
+ IMPLEMENTS THEN stdout contains a single line
+ n=$(wc -l < "$DATADIR/stdout")
+ if [ "$n" != 1 ]
+ then
+ die "stdout contains $n lines, not 1"
+ fi
+
+ IMPLEMENTS THEN stdout contains no spaces
+ n=$(tr < "$DATADIR/stdout" -cd ' ' | wc -c)
+ if [ "$n" != 0 ]
+ then
+ die "stdout contains spaces"
+ fi
+
+ IMPLEMENTS THEN stderr is empty
+ if [ -s "$DATADIR/stderr" ]
+ then
+ die "stderr is not empty"
+ fi