Merge lp:~sdqali/openstack-guest-agents/windows-agent-key-read-fix into lp:openstack-guest-agents

Proposed by sdqali
Status: Merged
Approved by: Chris Behrens
Approved revision: no longer in the source branch.
Merged at revision: 106
Proposed branch: lp:~sdqali/openstack-guest-agents/windows-agent-key-read-fix
Merge into: lp:openstack-guest-agents
Diff against target: 80 lines (+31/-10)
2 files modified
windows/xenserver/src/Rackspace.Cloud.Server.Agent.Specs/XenStoreSpec.cs (+22/-4)
windows/xenserver/src/Rackspace.Cloud.Server.Agent/XenStore.cs (+9/-6)
To merge this branch: bzr merge lp:~sdqali/openstack-guest-agents/windows-agent-key-read-fix
Reviewer Review Type Date Requested Status
Chris Behrens Pending
Review via email: mp+88308@code.launchpad.net

Description of the change

XenStore Agent ignores message keys whose files were removed by the client due to timeout. These will be reissued by the client.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'windows/xenserver/src/Rackspace.Cloud.Server.Agent.Specs/XenStoreSpec.cs'
2--- windows/xenserver/src/Rackspace.Cloud.Server.Agent.Specs/XenStoreSpec.cs 2011-03-02 21:56:51 +0000
3+++ windows/xenserver/src/Rackspace.Cloud.Server.Agent.Specs/XenStoreSpec.cs 2012-01-12 06:41:24 +0000
4@@ -1,4 +1,7 @@
5-using NUnit.Framework;
6+using System;
7+using System.Collections.Generic;
8+using NUnit.Framework;
9+using Rackspace.Cloud.Server.Agent.Configuration;
10 using Rackspace.Cloud.Server.Agent.Interfaces;
11 using Rhino.Mocks;
12
13@@ -17,12 +20,27 @@
14 }
15
16 [Test]
17- public void should_call_executable_implementation_with_the_right_parameters_when_writing_to_xenstore()
18+ public void Should_call_executable_implementation_with_the_right_parameters_when_writing_to_xenstore()
19 {
20-
21 xenStore.Write("name1", "value1");
22-
23 executable.AssertWasCalled(x => x.Run(Constants.XenClientPath, "write data/guest/name1 value1"));
24 }
25+
26+ [Test]
27+ public void Should_Ignore_MessageKeys_For_Which_The_File_Was_Removed()
28+ {
29+ var messageKey = Guid.NewGuid().ToString();
30+ executable.Expect(process => process.Run(Constants.XenClientPath, "dir " + Constants.WritableDataHostBase)).Return(ExecutableResult(messageKey));
31+ executable.Expect(
32+ process => process.Run(Constants.XenClientPath, string.Format("read data/host/{0}", messageKey))).Return(
33+ ExecutableResult(string.Format("reading data/host/{0}: The system cannot find the file specified.", messageKey)));
34+ var commands = xenStore.GetCommands();
35+ Assert.IsTrue(commands.Count == 0);
36+ }
37+
38+ private static ExecutableResult ExecutableResult(string messageKey)
39+ {
40+ return new ExecutableResult { Output = new List<string>{messageKey} };
41+ }
42 }
43 }
44
45=== modified file 'windows/xenserver/src/Rackspace.Cloud.Server.Agent/XenStore.cs'
46--- windows/xenserver/src/Rackspace.Cloud.Server.Agent/XenStore.cs 2011-03-04 00:43:41 +0000
47+++ windows/xenserver/src/Rackspace.Cloud.Server.Agent/XenStore.cs 2012-01-12 06:41:24 +0000
48@@ -13,6 +13,7 @@
49 // License for the specific language governing permissions and limitations
50 // under the License.
51
52+using System;
53 using System.Collections.Generic;
54 using Rackspace.Cloud.Server.Agent.Configuration;
55 using Rackspace.Cloud.Server.Agent.Interfaces;
56@@ -34,16 +35,18 @@
57 var messageKeysAsUuids = Read(Constants.WritableDataHostBase).ValidateAndClean();
58 IList<Command> commands = new List<Command>();
59
60- foreach (var messageKey in messageKeysAsUuids) {
61- var command = new Json<Command>().Deserialize(ReadKey(messageKey));
62- command.key = messageKey;
63- commands.Add(command);
64+ foreach (var messageKey in messageKeysAsUuids) {
65+ var result = ReadKey(messageKey);
66+ if (result.Contains("The system cannot find the file specified.")) continue;
67+ var command = new Json<Command>().Deserialize(result);
68+ command.key = messageKey;
69+ commands.Add(command);
70 }
71-
72 return commands;
73 }
74
75- public string ReadKey(string key) {
76+ public string ReadKey(string key)
77+ {
78 var result = _executableProcess.Run(Constants.XenClientPath, "read " + Constants.Combine(Constants.WritableDataHostBase, key));
79 return result.Output.First();
80 }

Subscribers

People subscribed via source and target branches