01-set-ubunut-mirror ignores DIB_DISTRIBUTION_MIRROR

Bug #1808359 reported by Valery Tschopp
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
diskimage-builder
Fix Released
Undecided
Manuel Torrinha

Bug Description

The diskimage_builder/elements/ubuntu/pre-install.d/01-set-ubuntu-mirror script just ignore DIB_DISTRIBUTION_MIRROR if no DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE is set.

The check is wrong:

    if [[ "$line" =~ ${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-} ]]; then

It matches all lines if DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE is not set.

So DIB_DISTRIBUTION_MIRROR will never be used to patch the /etc/apt/sources.list file.

Workaround:

    if [[ "$line" =~ ${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-X_IGNORED_LINE_X} ]]; then

Setting a default value for DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE should fix it.

Revision history for this message
Valery Tschopp (valery-tschopp) wrote :

The check (see below) always matches on Ubunut Xenial 16.04.5 with bash version 4.3.48(1)-release

line="foobar"
if [[ "$line" =~ ${DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE:-} ]] ; then echo $line match; fi
foobar match

Revision history for this message
Manuel Torrinha (t0rrant) wrote :

Valery, thanks a lot for your find, at the moment I'm working around the issue by setting both the DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE and the DIB_DISTRIBUTION_MIRROR:

  export DIB_DISTRIBUTION_MIRROR="insert your desired mirror here"
  export DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE="workaround.for.#1808359"

Revision history for this message
Manuel Torrinha (t0rrant) wrote :

I believe the intention here should to use the '==' operator instead of the '=~' operator, as the former compares two strings. The latter evaluates the string on the right of the operator as a regular expression, and it seems that when it's empty it matches everything:

```
$ [[ "asd" =~ "b" ]]; echo $?
1
$ [[ "asd" =~ "a" ]]; echo $?
0
$ [[ "asd" =~ "s" ]]; echo $?
0
$ [[ "asd" =~ "d" ]]; echo $?
0
$ [[ "asd" =~ "sd" ]]; echo $?
0
$ [[ "asd" =~ "" ]]; echo $?
0
```

From the chapter 3.2.4.2 (Conditional Constructs), of the bash reference:

"An additional binary operator, ‘=~’, is available, with the same precedence as ‘==’ and ‘!=’. When it is used, the string to the right of the operator is considered a POSIX extended regular expression and matched accordingly (as in regex3)). The return value is 0 if the string matches the pattern, and 1 otherwise. If the regular expression is syntactically incorrect, the conditional expression’s return value is 2."

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html

Changing the operator to '==' should fix this issue.

Revision history for this message
Manuel Torrinha (t0rrant) wrote :

After reviewing the documentation for the ubuntu element, it is expected to be an extended regular expression, however it should be checked if the variable is an empty string or not.

Changed in diskimage-builder:
assignee: nobody → t0rrant (t0rrant)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to diskimage-builder (master)

Reviewed: https://review.opendev.org/675294
Committed: https://git.openstack.org/cgit/openstack/diskimage-builder/commit/?id=a38ac762f12e2e7fde431c7091cc33371aa53cc4
Submitter: Zuul
Branch: master

commit a38ac762f12e2e7fde431c7091cc33371aa53cc4
Author: Manuel Torrinha <email address hidden>
Date: Thu Aug 8 12:12:19 2019 +0100

    Fixes DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE matching when empty

     - DIB_DISTRIBUTION_MIRROR_UBUNTU_IGNORE matches when it is empty or not
     set and DIB_DISTRIBUTION_MIRROR is being used. Checking for it being
     set and not empty solves this.
     - Normalizing bash conditionals for readability

    Closes-Bug: #1808359
    Change-Id: I87853fcda4c8b29a3f1720a2778debeb3acc3a53
    Signed-off-by: Manuel Torrinha <email address hidden>

Changed in diskimage-builder:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.