Patchwork [RFC,2/2] sanity: implement network connectivity test

login
register
mail settings
Submitter Joshua Lock
Date June 29, 2011, 9:55 p.m.
Message ID <dba23bdca8e1eec8eae537bf563fd26e148614df.1309383978.git.josh@linux.intel.com>
Download mbox | patch
Permalink /patch/6713/
State New, archived
Headers show

Comments

Joshua Lock - June 29, 2011, 9:55 p.m.
Sanity test to verify files can be fetched from the network using git, http
and https fetchers point users at a page to help get set up in the case of a
failure.

Requires a variable CONNECTIVITY_CHECK_URIS to be set, using the same pattern
as SRC_URI, of URI's to test against.
The variable CONNECTIVITY_CHECK_MSG can be set to provide a custom error
message, such as a pointer to some help, when this check fails.

Addresses [YOCTO #933]

Signed-off-by: Joshua Lock <josh@linux.intel.com>
---
 meta/classes/sanity.bbclass |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
Richard Purdie - July 7, 2011, 12:31 p.m.
On Wed, 2011-06-29 at 14:55 -0700, Joshua Lock wrote:
> Sanity test to verify files can be fetched from the network using git, http
> and https fetchers point users at a page to help get set up in the case of a
> failure.
> 
> Requires a variable CONNECTIVITY_CHECK_URIS to be set, using the same pattern
> as SRC_URI, of URI's to test against.
> The variable CONNECTIVITY_CHECK_MSG can be set to provide a custom error
> message, such as a pointer to some help, when this check fails.
> 
> Addresses [YOCTO #933]
> 
> Signed-off-by: Joshua Lock <josh@linux.intel.com>

Merged to master, thanks.

Richard

Patch

diff --git a/meta/classes/sanity.bbclass b/meta/classes/sanity.bbclass
index 720777a..c9d37c9 100644
--- a/meta/classes/sanity.bbclass
+++ b/meta/classes/sanity.bbclass
@@ -35,6 +35,8 @@  def check_sanity_tmpdir_change(tmpdir, data):
 
     # Check that TMPDIR isn't on a filesystem with limited filename length (eg. eCryptFS)
     testmsg = check_create_long_filename(tmpdir, "TMPDIR")
+    # Check that we can fetch from various network transports
+    testmsg = testmsg + check_connectivity(data)
     return testmsg
         
 def check_sanity_version_change(data):
@@ -79,6 +81,41 @@  def check_create_long_filename(filepath, pathname):
             return "Failed to create a file in %s: %s" % (pathname, strerror)
     return ""
 
+def check_connectivity(d):
+    # URI's to check can be set in the CONNECTIVITY_CHECK_URIS variable
+    # using the same syntax as for SRC_URI. If the variable is not set
+    # the check is skipped
+    test_uris = (bb.data.getVar('CONNECTIVITY_CHECK_URIS', d, True) or "").split()
+    retval = ""
+
+    # Only check connectivity if network enabled and the
+    # CONNECTIVITY_CHECK_URIS are set
+    network_enabled = not bb.data.getVar('BB_NO_NETWORK', d, True)
+    check_enabled = len(test_uris)
+    if check_enabled and network_enabled:
+        data = bb.data.createCopy(d)
+        bookmark = os.getcwd()
+        dldir = bb.data.expand('${TMPDIR}/sanity', data)
+        bb.data.setVar('DL_DIR', dldir, data)
+
+        try:
+            fetcher = bb.fetch2.Fetch(test_uris, data)
+            fetcher.download()
+            fetcher.clean(test_uris)
+        except Exception:
+            # Allow the message to be configured so that users can be
+            # pointed to a support mechanism.
+            msg = bb.data.getVar('CONNECTIVITY_CHECK_MSG', d, True) or ""
+            if len(msg) == 0:
+                msg = "Failed to fetch test data from the network. Please ensure your network is configured correctly.\n"
+            retval = msg
+        finally:
+            # Make sure we tidy up the cruft
+            oe.path.remove(dldir)
+            os.chdir(bookmark)
+
+    return retval
+
 def check_sanity(e):
     from bb import note, error, data, __version__