OSSTest: get host free memory size
cover OSSTest: get host free memory size
Originally ts-debian-hvm-install deliberately asks for large amount of guest memory, but the host may not have enough free memory to create the guest.
This patch series makes ts-debian-hvm-install start with a conservative value and only increase guest memory size if it can be satisfied.
Wei.
Wei Liu (2):
TestSupport.pm: introduce host_get_free_memory
ts-debian-hvm-install: fix guest memory size
Osstest/TestSupport.pm | 10 ++++++++++ ts-debian-hvm-install | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.10.4
PATCH 1/2 TestSupport.pm: introduce host_get_free_memory
... which returns the size of free memory in MB.
--- Osstest/TestSupport.pm | 10 ++++++++++ 1 file changed, 10 insertions(+)
Osstest/TestSupport.pm +10 -0
@@ -79,6 +79,7 @@ BEGIN { remote_perl_script_open remote_perl_script_done host_reboot target_reboot target_reboot_hard target_choose_vg target_umount_lv target_await_down + host_get_free_memory target_ping_check_down target_ping_check_up target_kernkind_check target_kernkind_console_inittab
@@ -915,6 +916,15 @@ sub host_reboot ($) { }); } +sub host_get_free_memory($$) { + my ($ho,$toolstack) = @_; + # The line is as followed: + # free_memory : XXXX + my $cmd = "$toolstack info | grep free_memory | awk {'print \$3'}"; + my $free_memory_mb = target_cmd_root($ho, $cmd, 10); + return $free_memory_mb; +} + sub target_reboot ($) { my ($ho) = @_; target_cmd_root($ho, "init 6");
Signature · 1 line
1.7.10.4
Re: [PATCH 1/2] TestSupport.pm: introduce host_get_free_memory
Wei Liu writes ("[PATCH 1/2] TestSupport.pm: introduce host_get_free_memory"):
Quoted 1 line
... which returns the size of free memory in MB.
...
Osstest/TestSupport.pm sub host_reboot ($) { · line 926
Quoted 8 lines
Osstest/TestSupport.pm +8
-0+sub host_get_free_memory($$) { + my ($ho,$toolstack) = @_; + # The line is as followed: + # free_memory : XXXX + my $cmd = "$toolstack info | grep free_memory | awk {'print \$3'}"; + my $free_memory_mb = target_cmd_root($ho, $cmd, 10); + return $free_memory_mb; +}
Surely it would be better do to the parsing on the control host in Perl rather than sending grep/awk runes to the target ? One regexp ought to do it.
Also, did you test this ? target_cmd_root doesn't return you the output.
Thanks,
Ian.
Re: [PATCH 1/2] TestSupport.pm: introduce host_get_free_memory
Quoted 16 lines · Ian Jackson
Wei Liu writes ("[PATCH 1/2] TestSupport.pm: introduce
host_get_free_memory"):Quoted 1 line
... which returns the size of free memory in MB.
...
Osstest/TestSupport.pm sub host_reboot ($) { · line 926
Quoted 8 lines
Osstest/TestSupport.pm +8
-0+sub host_get_free_memory($$) { + my ($ho,$toolstack) = @_; + # The line is as followed: + # free_memory : XXXX + my $cmd = "$toolstack info | grep free_memory | awk {'print \$3'}"; + my $free_memory_mb = target_cmd_root($ho, $cmd, 10); + return $free_memory_mb; +}Surely it would be better do to the parsing on the control host in Perl rather than sending grep/awk runes to the target ? One regexp ought to do it.
OK.
Quoted 3 lines
Also, did you test this ?
target_cmd_rootdoesn't return you the output.
I tested with a dummy ts- script (it's in fact ts-debian-hvm-install with most operations removed) it did print out the value.
If it's not the right function to use, what do you suggeust?
Wei.
Quoted 2 lines
Thanks,
Ian.
Re: [PATCH 1/2] TestSupport.pm: introduce host_get_free_memory
Wei Liu writes ("Re: [PATCH 1/2] TestSupport.pm: introduce host_get_free_memory"):
Quoted 6 lines · Ian Jackson
Quoted 2 lines
Also, did you test this ?
target_cmd_rootdoesn't return you the output.I tested with a dummy ts- script (it's in fact ts-debian-hvm-install with most operations removed) it did print out the value.
I think if you use target_cmd_root, the stdout from the command ends up on the stdout from the ts-* script (ie, in production, in the step transcript logfile). Is that perhaps what you saw ?
Quoted 1 line
If it's not the right function to use, what do you suggeust?
I think you want target_cmd_output_root.
Ian.
PATCH 2/2 ts-debian-hvm-install: fix guest memory size
In reply to Wei LiuChange the default memory size to 768MB, which is taken from ts-redhat-install. It should be a safe size to make this test case run on every host.
If the host has more than 5G free memory, change guest memory size to 5G to catch any error that triggers by crossing 4G boundary.
--- ts-debian-hvm-install | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
ts-debian-hvm-install +9 -1
@@ -32,7 +32,7 @@ $gn ||= 'ovmf'; our $ho= selecthost($whhost); -our $ram_mb= 6000; +our $ram_mb= 768; our $disk_mb= 10000; our $guesthost= "$gn.guest.osstest";
@@ -166,6 +166,14 @@ sub prep () { }); } +# If host has >5G free memory, create a guest with 5G memory to catch any error +# that triggers cross 4G boundary +our $host_freemem_mb = host_get_free_memory($ho, $toolstack); +if ($host_freemem_mb > 5000) { + $ram_mb = 5000; + logm("Host has $host_freemem_mb MB free memory, setting guest memory size to $ram_mb MB"); +} + if (!$stage) { prep(); guest_create($gho,$toolstack);
Signature · 1 line
1.7.10.4
Re: [PATCH 2/2] ts-debian-hvm-install: fix guest memory size
Wei Liu writes ("[PATCH 2/2] ts-debian-hvm-install: fix guest memory size"):
Quoted 3 lines
Change the default memory size to 768MB, which is taken from ts-redhat-install. It should be a safe size to make this test case run on every host.
...
Quoted 6 lines
ts-debian-hvm-install +1
-1-our $ram_mb= 6000; +our $ram_mb= 768; our $disk_mb= 10000; our $guesthost= "$gn.guest.osstest";
ts-debian-hvm-install sub prep () { · line 173
Quoted 8 lines
ts-debian-hvm-install +5
-0@@ -166,6 +166,14 @@ sub prep () { }); } +# If host has >5G free memory, create a guest with 5G memory to catch any error +# that triggers cross 4G boundary +our $host_freemem_mb = host_get_free_memory($ho, $toolstack); +if ($host_freemem_mb > 5000) { + $ram_mb = 5000;
If the host has exactly 5000, this will result in failure.
Also I don't like the separation of the two values for $ram_mb. The manifest constant at the top of the script is misleading given that the code might override it. I think you probably want to bury the magic constant(s) in with the setting code.
Thanks,
Ian.
Re: [PATCH 2/2] ts-debian-hvm-install: fix guest memory size
Quoted 14 lines · Ian Jackson
Wei Liu writes ("[PATCH 2/2] ts-debian-hvm-install: fix guest memory size"):
Quoted 3 lines
Change the default memory size to 768MB, which is taken from ts-redhat-install. It should be a safe size to make this test case run on every host.
...
Quoted 9 lines
ts-debian-hvm-install +1
-1-our $ram_mb= 6000; +our $ram_mb= 768; our $disk_mb= 10000; our $guesthost= "$gn.guest.osstest";@@ -166,6 +166,14 @@ sub prep () { }); }
Quoted 8 lines
ts-debian-hvm-install sub prep () { · line 173
Quoted 5 lines
ts-debian-hvm-install +5
-0+# If host has >5G free memory, create a guest with 5G memory to catch any error +# that triggers cross 4G boundary +our $host_freemem_mb = host_get_free_memory($ho, $toolstack); +if ($host_freemem_mb > 5000) { + $ram_mb = 5000;If the host has exactly 5000, this will result in failure.
That's because there's a "slack" required when building a domain. Hmm...
I can check for 5010 then set guest memory to 5000. What do you think?
Quoted 5 lines
Also I don't like the separation of the two values for $ram_mb. The manifest constant at the top of the script is misleading given that the code might override it. I think you probably want to bury the magic constant(s) in with the setting code.
Do you mean
if ($host_freemem_mb > 5000){
$ram_mb = 5000;
} else {
$ram_mb = 768; }
logm(...);
Wei.
Quoted 2 lines
Thanks,
Ian.
Re: [PATCH 2/2] ts-debian-hvm-install: fix guest memory size
Wei Liu writes ("Re: [PATCH 2/2] ts-debian-hvm-install: fix guest memory size"):
Quoted 4 lines
That's because there's a "slack" required when building a domain. Hmm...
I can check for 5010 then set guest memory to 5000. What do you think?
Yes. Perhaps the slop you allow ought to be a bit bigger.
Quoted 11 lines
Quoted 4 lines
Also I don't like the separation of the two values for $ram_mb. The manifest constant at the top of the script is misleading given that the code might override it. I think you probably want to bury the magic constant(s) in with the setting code.
Do you mean
if ($host_freemem_mb > 5000){ $ram_mb = 5000; } else { $ram_mb = 768;}
Yes, something like that. Perhaps:
my $ram_minslop = 100;
my $ram_lots = 5000;
if ($host_freemem_mb > $ram_lots + $ram_minslop) {
$ram_mb = $ram_lots;
} else {
$ram_mb = 768;
}because it avoids writing 5000 twice.
Ian.