Skip to content

Commit

Permalink
fixed the issues of network reset failure because of previous network…
Browse files Browse the repository at this point in the history
… names clash from snapshot
  • Loading branch information
kashivreddy committed Feb 20, 2014
1 parent c90d00d commit e0ef0b3
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
COMPANY = "Rackspace Cloud"
DESCRIPTION = "C#.NET Agent for Windows Virtual Machines"
CLR_VERSION = 'v3.5'
RELEASE_BUILD_NUMBER = "1.2.8.0"
RELEASE_BUILD_NUMBER = "1.2.8.1"

#Paths
SLN_FILE = File.join(ABSOLUTE_PATH,'src','WindowsConfigurationAgent.sln')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyVersion("1.2.8.1")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyVersion("1.2.8.1")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyVersion("1.2.8.1")]
41 changes: 37 additions & 4 deletions src/Rackspace.Cloud.Server.Agent.Specs/SetNetworkInterfaceSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Rackspace.Cloud.Server.Agent.WMI;
using Rackspace.Cloud.Server.Common.Logging;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;

namespace Rackspace.Cloud.Server.Agent.Specs {
public class SetNetworkInterfaceSpecBase {
Expand Down Expand Up @@ -197,24 +196,25 @@ public class SetNetworkInterfaceSpec_When_It_Goes_The_Happy_Path : SetNetworkInt
ExecutableProcessQueue.Expect(x => x.Go()).Repeat.Twice();

SetNetworkInterface = new SetNetworkInterface(ExecutableProcessQueue, WmiMacNetworkNameGetter, Logger, new IPFinder());
SetNetworkInterface.Execute(new List<NetworkInterface>{NetworkInterface});
}

[Test]
public void should_call_enable_on_disabled_interfaces_whose_macs_are_absent() {
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x => x.Enqueue("netsh", "interface set interface name=\"Lan2\" admin=ENABLED"));
// ExecutableProcessQueue.AssertWasCalled(x => x.Go());
}

[Test]
public void should_set_the_interface_for_dhcp_first_before_configuring_it() {
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x => x.Enqueue("netsh", "interface ip set address name=\"Lan1\" source=dhcp", new[] {"0", "1"}));
}

[Test]
public void should_configure_the_interface_correctly_with_the_gateway() {
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x =>
x.Enqueue("netsh",
Expand All @@ -223,12 +223,14 @@ public class SetNetworkInterfaceSpec_When_It_Goes_The_Happy_Path : SetNetworkInt

[Test]
public void should_configure_interface_with_the_dns_servers_as_dhcp() {
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x => x.Enqueue("netsh", "interface ip set dns name=\"Lan1\" source=dhcp", new[] {"0", "1"}));
}

[Test]
public void should_configure_interface_with_all_the_present_dns_servers() {
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x => x.Enqueue("netsh", "interface ip add dns name=\"Lan1\" addr=192.168.1.3 index=1"));
ExecutableProcessQueue.AssertWasCalled(
Expand All @@ -237,10 +239,41 @@ public class SetNetworkInterfaceSpec_When_It_Goes_The_Happy_Path : SetNetworkInt

[Test]
public void should_set_interface_name() {
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x => x.Enqueue("netsh", "interface set interface name=\"Lan1\" newname=\"Front End\""));
x => x.Enqueue("netsh", "interface set interface name=\"Lan1\" newname=\"Front End0\""));
}

[Test]
public void should_try_to_diff_name_if_set_interface_name_fails()
{
ExecutableProcessQueue.Expect(x => x.Go()).Throw(new UnsuccessfulCommandExecutionException("something", new ExecutableResult()));
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x => x.Enqueue("netsh", "interface set interface name=\"Lan1\" newname=\"Front End1\""));
}

[Test]
public void should_try_set_to_diff_name_if_set_interface_name_fails_for_no_of_retry_attempts()
{
const int noOfRetries = SetNetworkInterface.NO_OF_RETRIES_FOR_SETTING_INTERFACE_NAME;
ExecutableProcessQueue.Expect(x => x.Go()).Throw(new UnsuccessfulCommandExecutionException("something", new ExecutableResult())).Repeat.Times(noOfRetries);
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasCalled(
x => x.Enqueue("netsh", string.Format("interface set interface name=\"Lan1\" newname=\"Front End{0}\"", noOfRetries)));
}

[Test]
public void should_not_set_diff_name_if_set_interface_name_fails_for_more_than_retry_attempts()
{
const int noOfRetries = SetNetworkInterface.NO_OF_RETRIES_FOR_SETTING_INTERFACE_NAME;
ExecutableProcessQueue.Expect(x => x.Go()).Throw(new UnsuccessfulCommandExecutionException("something", new ExecutableResult())).Repeat.Times(noOfRetries+1);
SetNetworkInterface.Execute(new List<NetworkInterface> { NetworkInterface });
ExecutableProcessQueue.AssertWasNotCalled(
x => x.Enqueue("netsh", string.Format("interface set interface name=\"Lan1\" newname=\"Front End{0}\"", noOfRetries+1)));
}


[TearDown]
public void Teardown() {
ExecutableProcessQueue.VerifyAllExpectations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyVersion("1.2.8.1")]
28 changes: 23 additions & 5 deletions src/Rackspace.Cloud.Server.Agent/Actions/SetNetworkInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Rackspace.Cloud.Server.Agent.Configuration;
using Rackspace.Cloud.Server.Agent.Interfaces;
using Rackspace.Cloud.Server.Agent.Utilities;
Expand All @@ -25,13 +24,15 @@

namespace Rackspace.Cloud.Server.Agent.Actions
{

public interface ISetNetworkInterface
{
void Execute(List<NetworkInterface> networkInterfaces);
}

public class SetNetworkInterface : ISetNetworkInterface
{
public const int NO_OF_RETRIES_FOR_SETTING_INTERFACE_NAME = 10;
private readonly IExecutableProcessQueue _executableProcessQueue;
private readonly IWmiMacNetworkNameGetter _wmiMacNetworkNameGetter;
private readonly ILogger _logger;
Expand Down Expand Up @@ -87,10 +88,27 @@ private void SetNetworkInterfaceValues(NetworkInterface networkInterface, string
SetupDns(interfaceName, networkInterface);
}

if (interfaceName != networkInterface.label)
_executableProcessQueue.Enqueue("netsh", String.Format("interface set interface name=\"{0}\" newname=\"{1}\"", interfaceName, networkInterface.label));

_executableProcessQueue.Go();

SetInterfaceName(networkInterface, interfaceName, 0);
}

private void SetInterfaceName(NetworkInterface networkInterface, string interfaceName, int count)
{
if (interfaceName != networkInterface.label)
_executableProcessQueue.Enqueue("netsh",
String.Format("interface set interface name=\"{0}\" newname=\"{1}\"",
interfaceName, networkInterface.label + count));
try
{
_executableProcessQueue.Go();
}
catch (UnsuccessfulCommandExecutionException e)
{
_logger.Log(string.Format("Failed to setinterface name to {0} retrying", networkInterface.label + count));
if (count < NO_OF_RETRIES_FOR_SETTING_INTERFACE_NAME)
SetInterfaceName(networkInterface, interfaceName, ++count);
}
}

private void SetupIpv6Interface(string interfaceName, NetworkInterface networkInterface)
Expand Down Expand Up @@ -168,7 +186,7 @@ private void CleanseInterfaceForSetup(string interfaceName)
interfaceName), new[] { "0", "1" });
foreach (var ipv6Address in _ipFinder.findIpv6Addresses(interfaceName))
{
#region Windows 2012 Hack
#region Windows 2012 Hack
// - Adding an ipv6 interface address and removing it, if not the delete ipv6 address fails with "The system cannot find the file specified."
var addAddresscommand = string.Format("interface ipv6 add address interface=\"{0}\" address=1::",
interfaceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyVersion("1.2.8.1")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyVersion("1.2.8.1")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.8.0")]
[assembly: AssemblyVersion("1.2.8.1")]

0 comments on commit e0ef0b3

Please sign in to comment.