Merge ~alextu/plainbox-provider-pc-sanity:also-check-oem-fix-from-allowing-list into plainbox-provider-pc-sanity:master

Proposed by Alex Tu
Status: Merged
Merged at revision: a86ccc2a1bee7ba25dfdcb7426603f517c28e180
Proposed branch: ~alextu/plainbox-provider-pc-sanity:also-check-oem-fix-from-allowing-list
Merge into: plainbox-provider-pc-sanity:master
Diff against target: 188 lines (+96/-75)
2 files modified
bin/screen-pkg-not-public.sh (+95/-0)
units/pc-sanity/pc-sanity-screen-oem-gaps.pxu (+1/-75)
Reviewer Review Type Date Requested Status
jeremyszu (community) Approve
Yuan-Chen Cheng (community) Needs Fixing
Kai-Chuan Hsieh Pending
Shengyao Xue Pending
Canonical Mainstream Pending
Rex Tsai Pending
Alex Tu Pending
Review via email: mp+389642@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Tu (alextu) wrote :
Revision history for this message
Yuan-Chen Cheng (ycheng-twn) wrote :

Please fix shellcheck error on the new shell script.

review: Needs Fixing
Revision history for this message
Alex Tu (alextu) wrote :

fixed the warning from shellcheck

a failed case that target machine installed version that not on public archive:
https://pastebin.canonical.com/p/tmYPMZSc6n/

Revision history for this message
jeremyszu (os369510) wrote :

so far looks good to me.
I'll have the other proposal for fixing it doesn't work on Stella/Sutton machine.
Please ask someone to test it on somerville machine.

review: Approve
Revision history for this message
Alex Tu (alextu) wrote :

a test report shows it works as expected : https://paste.ubuntu.com/p/3B7NMnRKhZ/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/screen-pkg-not-public.sh b/bin/screen-pkg-not-public.sh
2new file mode 100755
3index 0000000..71887d7
4--- /dev/null
5+++ b/bin/screen-pkg-not-public.sh
6@@ -0,0 +1,95 @@
7+#!/bin/bash
8+
9+set -e
10+allowlist_git="https://git.launchpad.net/~oem-solutions-engineers/pc-enablement/+git/oem-gap-allow-list"
11+oem=""
12+platform=""
13+allowlst_folder=""
14+STATUS="pass"
15+clean() {
16+ rm -rf "$allowlst_folder"
17+ [ -z "$1" ] || exit "$1"
18+ [ "$STATUS" != "pass" ] && exit 1
19+ exit 0
20+}
21+prepare() {
22+ oem="$(grep -q sutton <(ubuntu-report show | grep DCD) && echo sutton)" ||\
23+ oem="$(grep -q stella <(ubuntu-report show | grep DCD) && echo stella)" ||\
24+ oem="$(grep -q somerville <(ubuntu-report show | grep DCD) && echo somerville)" ||\
25+ (>&2 echo "[ERROR][CODE]got an empty OEM codename in ${FUNCNAME[1]}" && clean 1)
26+ case "$oem" in
27+ "somerville")
28+ platform="$(ubuntu-report show | grep DCD | awk -F'+' '{print $2}')"
29+ ;;
30+ "sutton")
31+ platform_meta="$(dpkg-query -W -f='${Package}\n' "oem-""$oem"".*-meta")"
32+ oem="$(echo "$platform_meta" | cut -d'-' -f2 )"
33+ platform="$(echo "$platform_meta" | cut -d'-' -f3 )"
34+ ;;
35+ "stella")
36+ platform_meta="$(dpkg-query -W -f='${Package}\n' "oem-""$oem"".*-meta")"
37+ oem="$(echo "$platform_meta" | cut -d'-' -f2 )"
38+ platform="$(echo "$platform_meta" | cut -d'-' -f3 )"
39+ ;;
40+ *)
41+ >&2 echo "[ERROR][CODE]we should not be here in ${FUNCNAME[1]} : ${LINENO}" && clean 1
42+ ;;
43+ esac
44+ [ -z "$platform" ] && (>&2 echo "[ERROR][CODE]got an empty platform name for $oem in ${FUNCNAME[1]}" && clean 1)
45+ (sudo apt-get update > /dev/null || (>&2 echo "[ERROR]apt-get update failed, please check it." | exit 1)) && sudo apt-get install -y git > /dev/null
46+ echo "[INFO] getting allowlist from $allowlist_git."
47+ [ -n "$allowlist_git" ] &&\
48+ (git clone --depth=1 "$allowlist_git" || (>&2 echo "[ERROR]git clone ""$allowlist_git"" filed, please check it." | exit 1)) &&\
49+ allowlst_folder="$PWD"/"$(basename "$allowlist_git")"
50+ echo "[INFO] git hash of current allowlist: $(git -C "$allowlst_folder" rev-parse --short HEAD)"
51+}
52+pkg_need_allowing() {
53+ [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[1]}" && clean 1
54+ >&2 echo "[ERROR] Please send a MP to $allowlist_git for manager review $1" && STATUS="failed"
55+}
56+pkg_need_update() {
57+ [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[1]}" && clean 1
58+ >&2 echo "[ERROR] find a update-able pkg: $1 $2" && pkg_need_allowing "$1"
59+}
60+if_allowing() {
61+ local allowed="NO"
62+ [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[1]}" && clean 1
63+
64+ # check if the pkg on allow list.
65+ for F in "$allowlst_folder"/testtools "$allowlst_folder"/common "$allowlst_folder"/"$oem"/common "$allowlst_folder"/"$oem"/"$platform"; do
66+ [ -f "$F" ] && while IFS= read -r green_light; do
67+ [ "$1" == "$green_light" ] && echo "[INFO] manager gave a greenlight for :" "$1" "$2" && allowed="YES"
68+ done < "$F"
69+ done
70+ if [ "$allowed" == "NO" ]; then
71+ return 1
72+ else
73+ return 0
74+ fi
75+}
76+pkg_not_public() {
77+ [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in" "${FUNCNAME[1]}" && clean 1
78+ # check if the pkg on allow list.
79+ if_allowing "$1" || (>&2 echo "[ERROR] find a packge not on public archive:" "$1" "$2"&& pkg_need_allowing "$1")
80+}
81+prepare
82+echo "[INFO] staring screen all installed packages."
83+while IFS= read -r pkgname; do
84+ progress=">""$progress"
85+ [ "${#progress}" == "70" ] && echo "$progress" && progress=""
86+ pkgver="$(dpkg-query -W -f='${Version}' "$pkgname")"
87+ pub_madison="$(apt-cache madison "$pkgname")"
88+ can_pkgver="$(apt-cache policy "$pkgname" | grep Candidate | awk '{print $2}')"
89+ if [ -z "${pkgname##oem-fix*}" ]; then
90+ if_allowing "$pkgname" || pkg_need_allowing "$pkgname"
91+ fi
92+
93+ if [ -z "$pub_madison" ]; then
94+ pkg_not_public "$pkgname" "$pkgver"
95+ elif [ -n "${pub_madison##*$can_pkgver*}" ]; then
96+ pkg_not_public "$pkgname" "$pkgver"
97+ elif dpkg --compare-versions "$can_pkgver" "gt" "$pkgver"; then
98+ [ -z "${pkgver##*oem*}" ] || [ -z "${pkgver##*somerville*}" ] && pkg_need_update "$pkgname" "$pkgver"
99+ fi
100+done < <(dpkg -l | grep 'ii' | awk '{print $2}')
101+clean
102diff --git a/units/pc-sanity/pc-sanity-screen-oem-gaps.pxu b/units/pc-sanity/pc-sanity-screen-oem-gaps.pxu
103index 7284406..dbb2a75 100644
104--- a/units/pc-sanity/pc-sanity-screen-oem-gaps.pxu
105+++ b/units/pc-sanity/pc-sanity-screen-oem-gaps.pxu
106@@ -1,81 +1,7 @@
107 plugin: shell
108 category_id: com.canonical.plainbox::miscellanea
109 id: miscellanea/screen-pkg-not-public
110-command:
111- set -e
112- allowlist_git="https://git.launchpad.net/~oem-solutions-engineers/pc-enablement/+git/oem-gap-allow-list"
113- oem=""
114- platform=""
115- allowlst_folder=""
116- STATUS="pass"
117- clean() {
118- rm -rf "$allowlst_folder"
119- [ -z "$1" ] || exit $1
120- [ "$STATUS" != "pass" ] && exit 1
121- exit 0
122- }
123- prepare() {
124- oem="$(grep -q sutton <(ubuntu-report show | grep DCD) && echo sutton)" ||\
125- oem="$(grep -q stella <(ubuntu-report show | grep DCD) && echo stella)" ||\
126- oem="$(grep -q somerville <(ubuntu-report show | grep DCD) && echo somerville)" ||\
127- (>&2 echo "[ERROR][CODE]got an empty OEM codename in ${FUNCNAME[1]}" && clean 1)
128- case "$oem" in
129- "somerville")
130- platform="$(ubuntu-report show | grep DCD | awk -F'+' '{print $2}')"
131- ;;
132- "sutton")
133- platform_meta="$(dpkg-query -W -f='${Package}\n' "oem-"$oem".*-meta")"
134- oem="$(echo "$platform_meta" | cut -d'-' -f2 )"
135- platform="$(echo "$platform_meta" | cut -d'-' -f3 )"
136- ;;
137- "stella")
138- platform_meta="$(dpkg-query -W -f='${Package}\n' "oem-"$oem".*-meta")"
139- oem="$(echo "$platform_meta" | cut -d'-' -f2 )"
140- platform="$(echo "$platform_meta" | cut -d'-' -f3 )"
141- ;;
142- *)
143- >&2 echo "[ERROR][CODE]we should not be here in ${FUNCNAME[1]} : ${LINENO}" && clean 1
144- ;;
145- esac
146- [ -z "$platform" ] && (>&2 echo "[ERROR][CODE]got an empty platform name for $oem in ${FUNCNAME[1]}" && clean 1)
147- (sudo apt-get update > /dev/null || (>&2 echo "[ERROR]apt-get update failed, please check it." | exit 1)) && sudo apt-get install -y git > /dev/null
148- echo "[INFO] getting allowlist from $allowlist_git."
149- [ -n "$allowlist_git" ] &&\
150- (git clone --depth=1 "$allowlist_git" || (>&2 echo "[ERROR]git clone "$allowlist_git" filed, please check it." | exit 1)) &&\
151- allowlst_folder="$PWD"/"$(basename "$allowlist_git")"
152- echo "[INFO] git hash of current allowlist: $(git -C "$allowlst_folder" rev-parse --short HEAD)"
153- }
154- pkg_need_update() {
155- [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in ${FUNCNAME[1]}" && clean 1
156- >&2 echo "[ERROR] find a update-able pkg: $1 $2" && STATUS="failed"
157- }
158- pkg_not_public() {
159- [ -z "$1" ] && >&2 echo "[ERROR][CODE]got an empty pkg in" "${FUNCNAME[1]}" && clean 1
160- # check if the pkg on allow list.
161- for F in "$allowlst_folder"/testtools "$allowlst_folder"/common "$allowlst_folder"/"$oem"/common "$allowlst_folder"/"$oem"/"$platform"; do
162- [ -f "$F" ] && while IFS= read -r green_light; do
163- [ "$1" == "$green_light" ] && echo "[INFO] manager gave a greenlight for :" "$1" "$2" && return 0
164- done < "$F"
165- done
166- >&2 echo "[ERROR] find a packge not on public archive:" "$1" "$2"&& STATUS="failed"
167- }
168- prepare
169- echo "[INFO] staring screen all installed packages."
170- while IFS= read -r pkgname; do
171- progress=">""$progress"
172- [ "${#progress}" == "70" ] && echo "$progress" && progress=""
173- pkgver="$(dpkg-query -W -f='${Version}' "$pkgname")"
174- pub_madison="$(apt-cache madison "$pkgname")"
175- can_pkgver="$(apt-cache policy "$pkgname" | grep Candidate | awk '{print $2}')"
176- if [ -z "$pub_madison" ]; then
177- pkg_not_public "$pkgname" "$pkgver"
178- elif [ -n "${pub_madison##*$can_pkgver*}" ]; then
179- pkg_not_public "$pkgname" "$pkgver"
180- elif dpkg --compare-versions "$can_pkgver" "gt" "$pkgver"; then
181- [ -z "${pkgver##*oem*}" ] || [ -z "${pkgver##*somerville*}" ] && pkg_need_update "$pkgname" "$pkgver"
182- fi
183- done < <(dpkg -l | grep 'ii' | awk '{print $2}')
184- clean
185+command: screen-pkg-not-public.sh
186 _summary: check if pkgs not on public archive
187 _description:
188 check if pkgs not on public archive

Subscribers

People subscribed via source and target branches