|
14 | 14 | IMAGE_DIR_PREFIX,
|
15 | 15 | IMAGE_PREFIX,
|
16 | 16 | run_command,
|
| 17 | + default_sigpipe, |
17 | 18 | )
|
18 | 19 | from .onie import OnieInstallerBootloader
|
19 |
| -from .onie import default_sigpipe |
20 | 20 |
|
21 |
| -MACHINE_CONF = "installer/machine.conf" |
| 21 | +PLATFORMS_ASIC = "installer/platforms_asic" |
22 | 22 |
|
23 | 23 | class GrubBootloader(OnieInstallerBootloader):
|
24 | 24 |
|
@@ -85,35 +85,34 @@ def remove_image(self, image):
|
85 | 85 | run_command('grub-set-default --boot-directory=' + HOST_PATH + ' 0')
|
86 | 86 | click.echo('Image removed')
|
87 | 87 |
|
| 88 | + def platform_in_platforms_asic(self, platform, image_path): |
| 89 | + """ |
| 90 | + For those images that don't have devices list builtin, 'tar' will have non-zero returncode. |
| 91 | + In this case, we simply return True to make it worked compatible as before. |
| 92 | + Otherwise, we can grep to check if platform is inside the supported target platforms list. |
| 93 | + """ |
| 94 | + with open(os.devnull, 'w') as fnull: |
| 95 | + p1 = subprocess.Popen(["sed", "-e", "1,/^exit_marker$/d", image_path], stdout=subprocess.PIPE, preexec_fn=default_sigpipe) |
| 96 | + p2 = subprocess.Popen(["tar", "xf", "-", PLATFORMS_ASIC, "-O"], stdin=p1.stdout, stdout=subprocess.PIPE, stderr=fnull, preexec_fn=default_sigpipe) |
| 97 | + p3 = subprocess.Popen(["grep", "-Fxq", "-m 1", platform], stdin=p2.stdout, preexec_fn=default_sigpipe) |
| 98 | + |
| 99 | + p2.wait() |
| 100 | + if p2.returncode != 0: |
| 101 | + return True |
| 102 | + |
| 103 | + # Code 0 is returned by grep as a result of found |
| 104 | + p3.wait() |
| 105 | + return p3.returncode ==0 |
| 106 | + |
88 | 107 | def verify_image_platform(self, image_path):
|
89 | 108 | if not os.path.isfile(image_path):
|
90 | 109 | return False
|
91 | 110 |
|
92 |
| - # Get running platform's ASIC |
93 |
| - try: |
94 |
| - version_info = device_info.get_sonic_version_info() |
95 |
| - if version_info: |
96 |
| - asic_type = version_info['asic_type'] |
97 |
| - else: |
98 |
| - asic_type = None |
99 |
| - except (KeyError, TypeError) as e: |
100 |
| - click.echo("Caught an exception: " + str(e)) |
101 |
| - |
102 |
| - # Get installing image's ASIC |
103 |
| - p1 = subprocess.Popen(["sed", "-e", "1,/^exit_marker$/d", image_path], stdout=subprocess.PIPE, preexec_fn=default_sigpipe) |
104 |
| - p2 = subprocess.Popen(["tar", "xf", "-", MACHINE_CONF, "-O"], stdin=p1.stdout, stdout=subprocess.PIPE, preexec_fn=default_sigpipe) |
105 |
| - p3 = subprocess.Popen(["sed", "-n", r"s/^machine=\(.*\)/\1/p"], stdin=p2.stdout, stdout=subprocess.PIPE, preexec_fn=default_sigpipe, text=True) |
106 |
| - |
107 |
| - stdout = p3.communicate()[0] |
108 |
| - image_asic = stdout.rstrip('\n') |
109 |
| - |
110 |
| - # Return false if machine is not found or unexpected issue occur |
111 |
| - if not image_asic: |
112 |
| - return False |
| 111 | + # Get running platform |
| 112 | + platform = device_info.get_platform() |
113 | 113 |
|
114 |
| - if asic_type == image_asic: |
115 |
| - return True |
116 |
| - return False |
| 114 | + # Check if platform is inside image's target platforms |
| 115 | + return self.platform_in_platforms_asic(platform, image_path) |
117 | 116 |
|
118 | 117 | @classmethod
|
119 | 118 | def detect(cls):
|
|
0 commit comments