You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Zack Shoylev <no...@github.com> on 2013/06/26 21:43:11 UTC

[jclouds-chef] Fixes tests under windows. (#5)

Some of the files are generated with system-specific line endings (probably the keys)
You can merge this Pull Request by running:

  git pull https://github.com/rackerlabs/jclouds-chef windows-test-fix

Or you can view, comment on it, or merge it online at:

  https://github.com/jclouds/jclouds-chef/pull/5

-- Commit Summary --

  * Fixes tests under windows.

-- File Changes --

    M core/src/test/java/org/jclouds/chef/functions/GroupToBootScriptTest.java (8)

-- Patch Links --

https://github.com/jclouds/jclouds-chef/pull/5.patch
https://github.com/jclouds/jclouds-chef/pull/5.diff


Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-chef #136](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-chef/136/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20191808

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-chef-pull-requests #6](https://jclouds.ci.cloudbees.com/job/jclouds-chef-pull-requests/6/) UNSTABLE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20193535

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Zack Shoylev <no...@github.com>.
> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>        replay(validatorKey);
>  
>        assertEquals(
> -            fn.apply("foo").render(OsFamily.UNIX),
> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),

It is probably because of Pems.java - it uses the system line separator, but I think it gets compared to a static resource file.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4900834

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi Barrera <no...@github.com>.
Will push to 1.6.x in a while.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20249845

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi Barrera <no...@github.com>.
Merged. Thanks Zack!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20249824

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-chef #137](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-chef/137/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20193508

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi Barrera <no...@github.com>.
> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>        replay(validatorKey);
>  
>        assertEquals(
> -            fn.apply("foo").render(OsFamily.UNIX),
> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),

It shouldn't break the functionality (need to test it, though), but if running jclouds-chef from a Windows machine to bootstrap, say, an Ubuntu, then we will be uploading to the Ubuntu node a script with a mix of Windows and UNIX line terminations. In the concrete case of chef, due to how the generated script works, it shouldn't be a problem, but the uploaded script will seem to have been bad generated.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4917621

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-chef-pull-requests #4](https://jclouds.ci.cloudbees.com/job/jclouds-chef-pull-requests/4/) UNSTABLE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20191592

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Andrew Phillips <no...@github.com>.
> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>        replay(validatorKey);
>  
>        assertEquals(
> -            fn.apply("foo").render(OsFamily.UNIX),
> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),

>  then we will be uploading to the Ubuntu node a script with a mix of Windows and UNIX line terminations

Just to be clear: you're saying this is what _currently_ happens? In that case, I'd also vote for fixing the problem rather than making the test failure go away - file generation for a specific platform should consistently use the line termination _for that platform_, independent of where the files are generated.

It's good the Chef doesn't trip over that, but it still looks like a bug to me.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4919012

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Andrew Phillips <no...@github.com>.
> @@ -108,7 +109,7 @@ public Statement apply(String group) {
>              String.format("chef_server_url \"%s\"", endpoint.get())));
>  
>        Statement createValidationPem = appendFile(chefConfigDir + "{fs}validation.pem",
> -            Splitter.on('\n').split(Pems.pem(validatorKey)));
> +            Splitter.on(Pattern.compile("(\\r\\n)|(\\n)")).split(Pems.pem(validatorKey)));

> It did not seem necessary here, unless you process millions of statements...?

If this won't be invoked often, let's indeed just leave as-is...

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4939767

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Andrew Phillips <no...@github.com>.
> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>        replay(validatorKey);
>  
>        assertEquals(
> -            fn.apply("foo").render(OsFamily.UNIX),
> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),

Ah, is that a bug in Pems? Either way, could you add a comment to explain?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4901778

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Zack Shoylev <no...@github.com>.
> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>        replay(validatorKey);
>  
>        assertEquals(
> -            fn.apply("foo").render(OsFamily.UNIX),
> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),

jclouds-chef seems to not be functionally impacted by this issue - is it? If fixed in code as opposed to tests, the trade-off is add to add complexity to increase consistency.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4916776

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi Barrera <no...@github.com>.
Closed #5.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Andrew Phillips <no...@github.com>.
>              Resources.toString(Resources.getResource("test_install_ruby." + ShellToken.SH.to(OsFamily.UNIX)),
>                    Charsets.UTF_8)
>                    + Resources.toString(
>                          Resources.getResource("test_install_rubygems." + ShellToken.SH.to(OsFamily.UNIX)),
>                          Charsets.UTF_8)
>                    + "gem install chef --no-rdoc --no-ri\n"
> -                  + Resources.toString(Resources.getResource("bootstrap.sh"), Charsets.UTF_8));
> +                  + Resources.toString(Resources.getResource("bootstrap.sh"), Charsets.UTF_8).replace("\r\n", "\n"));

Again, why does `bootstrap.sh` contain CRLFs in the first place?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4900620

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-chef #132](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-chef/132/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20151613

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi <ig...@gmail.com>.
I meant Zack :)

On 27 June 2013 00:48, Ignasi Barrera <no...@github.com> wrote:
>> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>>        replay(validatorKey);
>>
>>        assertEquals(
>> -            fn.apply("foo").render(OsFamily.UNIX),
>> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),
>
> Great investigations Zach! As you say, Pems.java seems to be the bad boy here: https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/crypto/Pems.java#L403
>
> I don't think it is a bug in Pems.java, because it will generate the PEM file with the line terminations according to the OS where it is being run.
>
> The bug is in Chef: basically in chef we are composing a script that will be uploaded to the node, and in the `render` method we tell the scriptbuilder in which target OS the script be executed, so it can be properly generated. The problem is that if we are generating the script in a Windows machine, we are passing a string literal (the private key in PEM format) with CRLF characters to be directly appended to a file, and the scriptbuilder does not manipulate the string provided by the user.
>
> I think the correct approach here would be to slightly modify [these lines](https://github.com/jclouds/jclouds-chef/blob/master/core/src/main/java/org/jclouds/chef/functions/GroupToBootScript.java?source=cc#L110-111) so they return an statement that overrides the render method to do the replacement of the line terminations when rendering to UNIX (rendering to Windows is still not supported in chef). That statement could be a decorator of the current `appendFile` that replaces the line terminations after the delegate statement renders the script fragment. This should also allow us to leave the tests unchanged.
>
> WDYT?
>
>
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/jclouds/jclouds-chef/pull/5/files#r4905205

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi Barrera <no...@github.com>.
> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>        replay(validatorKey);
>  
>        assertEquals(
> -            fn.apply("foo").render(OsFamily.UNIX),
> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),

Great investigations Zach! As you say, Pems.java seems to be the bad boy here: https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/crypto/Pems.java#L403

I don't think it is a bug in Pems.java, because it will generate the PEM file with the line terminations according to the OS where it is being run.

The bug is in Chef: basically in chef we are composing a script that will be uploaded to the node, and in the `render` method we tell the scriptbuilder in which target OS the script be executed, so it can be properly generated. The problem is that if we are generating the script in a Windows machine, we are passing a string literal (the private key in PEM format) with CRLF characters to be directly appended to a file, and the scriptbuilder does not manipulate the string provided by the user.

I think the correct approach here would be to slightly modify [these lines](https://github.com/jclouds/jclouds-chef/blob/master/core/src/main/java/org/jclouds/chef/functions/GroupToBootScript.java?source=cc#L110-111) so they return an statement that overrides the render method to do the replacement of the line terminations when rendering to UNIX (rendering to Windows is still not supported in chef). That statement could be a decorator of the current `appendFile` that replaces the line terminations after the delegate statement renders the script fragment. This should also allow us to leave the tests unchanged.

WDYT?



---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4905205

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi Barrera <no...@github.com>.
Pushed to 1.6.x and 1.5.x.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20257115

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-chef-pull-requests #2](https://jclouds.ci.cloudbees.com/job/jclouds-chef-pull-requests/2/) UNSTABLE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20151675

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Zack Shoylev <no...@github.com>.
> @@ -108,7 +109,7 @@ public Statement apply(String group) {
>              String.format("chef_server_url \"%s\"", endpoint.get())));
>  
>        Statement createValidationPem = appendFile(chefConfigDir + "{fs}validation.pem",
> -            Splitter.on('\n').split(Pems.pem(validatorKey)));
> +            Splitter.on(Pattern.compile("(\\r\\n)|(\\n)")).split(Pems.pem(validatorKey)));

I don't think it will be but I will change it just in case. 

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4940107

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-chef-pull-requests #5](https://jclouds.ci.cloudbees.com/job/jclouds-chef-pull-requests/5/) UNSTABLE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20191683

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Andrew Phillips <no...@github.com>.
> @@ -108,7 +109,7 @@ public Statement apply(String group) {
>              String.format("chef_server_url \"%s\"", endpoint.get())));
>  
>        Statement createValidationPem = appendFile(chefConfigDir + "{fs}validation.pem",
> -            Splitter.on('\n').split(Pems.pem(validatorKey)));
> +            Splitter.on(Pattern.compile("(\\r\\n)|(\\n)")).split(Pems.pem(validatorKey)));

Is it worth saving this as a constant rather than compiling this for every invocation? Or does `Pattern.compile` do this internally anyway?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4931164

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Andrew Phillips <no...@github.com>.
Thanks, @zack-shoylev 

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20281907

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-chef #128](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-chef/128/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20074792

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-chef-pull-requests #1](https://jclouds.ci.cloudbees.com/job/jclouds-chef-pull-requests/1/) UNSTABLE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20074961

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-chef #135](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-chef/135/) SUCCESS
This pull request looks good
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20191551

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Ignasi Barrera <no...@github.com>.
Great! +1

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5#issuecomment-20152002

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Andrew Phillips <no...@github.com>.
> @@ -129,14 +129,14 @@ public void testOneRecipe() throws IOException {
>        replay(validatorKey);
>  
>        assertEquals(
> -            fn.apply("foo").render(OsFamily.UNIX),
> +            fn.apply("foo").render(OsFamily.UNIX).replace("\r\n", "\n"),

If we're rendering for `UNIX`, why are there CRLFs in there in the first place, even if we're rendering on a Windows box? Or am I missing something?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4900610

Re: [jclouds-chef] Fixes tests under windows. (#5)

Posted by Zack Shoylev <no...@github.com>.
> @@ -108,7 +109,7 @@ public Statement apply(String group) {
>              String.format("chef_server_url \"%s\"", endpoint.get())));
>  
>        Statement createValidationPem = appendFile(chefConfigDir + "{fs}validation.pem",
> -            Splitter.on('\n').split(Pems.pem(validatorKey)));
> +            Splitter.on(Pattern.compile("(\\r\\n)|(\\n)")).split(Pems.pem(validatorKey)));

It does not do that internally I think. If you do a lot of processing usually you want it in a constants. It did not seem necessary here, unless you process millions of statements...?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-chef/pull/5/files#r4939594