Adding DSC MOF compilation for Linux tests

This commit is contained in:
John Kordich 2016-08-03 12:41:48 -07:00
parent 1492abeedc
commit 643533b6a8
14 changed files with 602 additions and 0 deletions

View file

@ -0,0 +1,169 @@
$originalPSModulePath = $env:PSModulePath
try
{
$env:DSC_HOME = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath dsc
# $env:PSMODULEPATH = $env:PSMODULEPATH + ";" + $env:DEVPATH + "Modules"
# $env:PSModulePath = "$($env:DEVPATH)\Modules"
Describe "DSC MOF Compilation" -tags "CI" {
It "Should be able to compile a MOF from a basic configuration" -Skip:$IsWindows {
[Scriptblock]::Create(@"
configuration DSCTestConfig
{
Node "localhost" {
nxFile f1
{
DestinationPath = "/tmp/file1";
}
}
}
DSCTestConfig
"@).Invoke()
Remove-Item -Force -Recurse -Path DSCTestConfig
}
It "Should be able to compile a MOF from another basic configuration" -Skip:$IsWindows {
[Scriptblock]::Create(@"
configuration DSCTestConfig
{
Node "localhost" {
nxScript f1
{
GetScript = "";
SetScript = "";
TestScript = "";
User = "root";
}
}
}
DSCTestConfig
"@).Invoke()
Remove-Item -Force -Recurse -Path DSCTestConfig
}
It "Should be able to compile a MOF from a complex configuration" -Skip:$IsWindows {
[Scriptblock]::Create(@"
Configuration WordPressServer{
Node CentOS{
#Ensure Apache packages are installed
nxPackage httpd {
Ensure = "Present"
Name = "httpd"
PackageManager = "yum"
}
#Include vhostdir
nxFile vHostDir{
DestinationPath = "/etc/httpd/conf.d/vhosts.conf"
Ensure = "Present"
Contents = "IncludeOptional /etc/httpd/sites-enabled/*.conf`n"
Type = "File"
}
nxFile vHostDirectory{
DestinationPath = "/etc/httpd/sites-enabled"
Type = "Directory"
Ensure = "Present"
}
#Ensure directory for Wordpress site
nxFile wpHttpDir{
DestinationPath = "/var/www/wordpress"
Type = "Directory"
Ensure = "Present"
Mode = "755"
}
#Ensure share directory
nxFile share{
DestinationPath = "/mnt/share"
Type = "Directory"
Ensure = "Present"
Mode = "755"
}
#Bind httpd to port 8080
nxFile HttpdPort{
DestinationPath = "/etc/httpd/conf.d/listen.conf"
Ensure = "Present"
Contents = "Listen 8080`n"
Type = "File"
}
#nfs mounts
nxScript nfsMount{
TestScript= "#!/bin/bash"
GetScript="#!/bin/bash"
SetScript="#!/bin/bash"
}
#Retrieve latest wordpress
nxFile WordPressTar{
SourcePath = "/mnt/share/latest.zip"
DestinationPath = "/tmp/wordpress.zip"
Checksum = "md5"
Type = "file"
DependsOn = "[nxScript]nfsMount"
}
#Extract wordpress if changed
nxArchive ExtractSite{
SourcePath = "/tmp/wordpress.zip"
DestinationPath = "/var/www/wordpress"
Ensure = "Present"
DependsOn = "[nxFile]WordpressTar"
}
#Set wp-config
#Fixup SE Linux context
#nxScript SELinuxContext{
#TestScript= "#!/bin/bash"
#GetScript = "#!/bin/bash"
#SetScript = "#!/bin/bash"
#}
#Disable SELinux
nxFileLine SELinux {
Filepath = "/etc/selinux/config"
DoesNotContainPattern = "SELINUX=enforcing"
ContainsLine = "SELINUX=disabled"
}
nxScript SELinuxHTTPNet{
GetScript = "#!/bin/bash`ngetsebool httpd_can_network_connect"
setScript = "#!/bin/bash`nsetsebool -P httpd_can_network_connect=1"
TestScript = "#!/bin/bash`n exit 1"
}
}
}
WordPressServer
"@).Invoke()
Remove-Item -Force -Recurse -Path WordPressServer
}
}
}
finally
{
$env:PSModulePath = $originalPSModulePath
}

View file

@ -0,0 +1,100 @@
// ===============================================================
// MetaConfiguration
// ===============================================================
[ClassVersion("1.0.0"),Description("Local Configuration Manager settings.")]
class MSFT_DSCMetaConfiguration
{
[Description ("The time interval between consecutive runs for reapplying the configuration to get to the desired state." )]
uint32 ConfigurationModeFrequencyMins;
[Description ("Reboot node if needed.")]
boolean RebootNodeIfNeeded;
[Description ("The configuration apply mode for the server."),
ValueMap {"ApplyOnly","ApplyAndMonitor","ApplyAndAutoCorrect"},
Values {"ApplyOnly","ApplyAndMonitor","ApplyAndAutoCorrect"}]
string ConfigurationMode;
[EmbeddedInstance("MSFT_Credential"),
Description ("Default credential to access resources." )]
string Credential;
[Description ("The refresh mode for the server. Valid values are Pull and Push." ),
ValueMap {"Push","Pull"},
Values {"Push","Pull"}]
string RefreshMode;
[Description ("The certificate ID used to locate the certificate." )]
string CertificateID;
[Description ("The configuration ID used to get the configuration from the pull server." )]
string ConfigurationID;
[Description ("Name of the configuration and module Download Manager." )]
string DownloadManagerName;
[Description ("Custom data that is specific to Download Manager." ),
EmbeddedInstance("MSFT_KeyValuePair")]
string DownloadManagerCustomData[];
[Description ("The time interval between consecutive runs to get the action from the server." )]
uint32 RefreshFrequencyMins;
[Description ("Overwrite modules when downloading from Pull Server." )]
boolean AllowModuleOverwrite;
[Read, Description("Current state of local configuration manager."),
ValueMap{"Ready","Busy","PendingReboot"},
Values{"Ready","Busy","PendingReboot"}]
string LocalConfigurationManagerState;
[Description ("Array of configuration download manager objects that contain location information to download configurations" ) ,
EmbeddedInstance("OMI_ConfigurationDownloadManager")]
string ConfigurationDownloadManagers[];
[Description ("Array of resource module managers pointing to a location to download missing DSCResources" ) ,
EmbeddedInstance("OMI_ResourceModuleManager")]
string ResourceModuleManagers[];
[Description ("Array of report managers pointing to a location that would help generate reports for DSC" ) ,
EmbeddedInstance("OMI_ReportManager")]
string ReportManagers[];
[EmbeddedInstance("MSFT_PartialConfiguration")] string PartialConfigurations[];
[Description ("The action after reboot the server."),
ValueMap {"ContinueConfiguration","StopConfiguration"},
Values {"ContinueConfiguration","StopConfiguration"}]
string ActionAfterReboot;
[Description ("The enumeration for DebugMode."),
ValueMap {"None","ForceModuleImport", "All", "ResourceScriptBreakAll"},
Values {"None","ForceModuleImport", "All", "ResourceScriptBreakAll"}]
string DebugMode[];
[Read, Description("Current version of local configuration manager.")]
string LCMVersion;
[Read, Description("Compatible versions of current local configuration manager.")]
string LCMCompatibleVersions[];
[Read, Description("Current state of local configuration manager."),
ValueMap{"Idle","Busy","PendingReboot","PendingConfiguration"},
Values{"Idle","Busy","PendingReboot","PendingConfiguration"}]
string LCMState;
[Read, Description("State detail of local configuration manager.")]
string LCMStateDetail;
[Description ("Number of days to retain configuration status history.")]
uint32 StatusRetentionTimeInDays;
[Read, Description("AgentId of the current Dsc Agent.")]
string AgentId;
boolean EnableSignatureValidation;
boolean DisableModuleSignatureValidation;
};

View file

@ -0,0 +1,207 @@
[Abstract, ClassVersion("1.0.0")]
class OMI_BaseResource
{
[required] string ResourceId;
[write] string SourceInfo;
[write] string DependsOn[];
[required] string ModuleName;
[required] string ModuleVersion;
[write] string ConfigurationName;
};
[Abstract, ClassVersion("1.0.0")]
class MSFT_KeyValuePair
{
[Key]
string Key;
[write]
string Value;
};
[Abstract, ClassVersion("1.0.0")]
class MSFT_BaseConfigurationProviderRegistration
{
[key] String ClassName;
String DSCEngineCompatVersion;
String DSCModuleVersion;
};
[ClassVersion("1.0.0")]
class MSFT_CimConfigurationProviderRegistration : MSFT_BaseConfigurationProviderRegistration
{
String Namespace;
};
[ClassVersion("1.0.0")]
class MSFT_PSConfigurationProviderRegistration : MSFT_BaseConfigurationProviderRegistration
{
String ModuleName;
};
[ClassVersion("1.0.0")]
class OMI_ConfigurationDocument
{
String Version;
String Author;
String Copyright;
String HelpInfoUri;
String ContentType;
String GenerationDate;
String GenerationHost;
String Name;
String MinimumCompatibleVersion;
String CompatibleVersionAdditionalProperties[];
String DocumentType;
};
[ClassVersion("1.0.0")]
class MSFT_Credential
{
[MaxLen ( 256 )]
string UserName;
string Password;
};
// ===============================================================
// OMI_MetaConfigurationResource
// ===============================================================
[ClassVersion("1.0.0"),
Description (
"Base schema for all Metaconfiguration resources." )]
class OMI_MetaConfigurationResource
{
[required]
string ResourceId;
[write]
string SourceInfo;
};
// ===============================================================
// Configuration Download Manager
// ===============================================================
[ClassVersion("1.0.0"),
Description("Class defining the configuration download manager" ) ]
class OMI_ConfigurationDownloadManager : OMI_MetaConfigurationResource
{
};
[ClassVersion("1.0.0"),
Description("Web download manager class inheriting from OMI_ConfigurationDownloadManager" )]
class MSFT_WebDownloadManager : OMI_ConfigurationDownloadManager
{
[Description ("String URL of the download manager location" ) , Key]
string ServerURL;
[Description ("The certificate ID used to locate the certificate." ) ]
string CertificateID;
[Description ("Boolean variable to allow unsecure connections" ) ]
boolean AllowUnsecureConnection;
[Description ("Registration Key with which to register with the Pull Server" ) ]
string RegistrationKey;
[Description ("The set of configuration names with which to register with the Pull Server.")]
string ConfigurationNames[];
};
// ===============================================================
// Report Managers
// ===============================================================
[ClassVersion("1.0.0"),
Description("Class defining a report manager") ]
class OMI_ReportManager : OMI_MetaConfigurationResource
{
};
[ClassVersion("1.0.0"),
Description("Web report manager class inheriting from OMI_ReportManager class") ]
class MSFT_WebReportManager : OMI_ReportManager
{
[Description ("URL of the server used by report manager." ) , Key]
string ServerURL;
[Description ("The certificate ID used to locate the certificate for secure connections." ) ]
string CertificateID;
[Description("Specifies whether report manager can use unsecure connection over http.")]
boolean AllowUnsecureConnection;
[Description ("Registration Key with which to register with the Reporting Server" ) ]
string RegistrationKey;
};
// ===============================================================
// ResourceModule Managers
// ===============================================================
[ClassVersion("1.0.0"), Description("Class defining the structure of resource module managers") ]
class OMI_ResourceModuleManager : OMI_MetaConfigurationResource
{
};
[ClassVersion("1.0.0"),
Description("Web resource module manager class inheriting from OMI_ResourceModuleManager") ]
class MSFT_WebResourceManager : OMI_ResourceModuleManager
{
[Description ("String URL of the resource module manager location" ) , Key]
string ServerURL;
[Description ("The certificate ID used to locate the certificate." ) ]
string CertificateID;
[Description ("Boolean variable to allow unsecure connections" ) ]
boolean AllowUnsecureConnection;
[Description ("Registration Key with which to register with the Resource Repository Web" ) ]
string RegistrationKey;
};
[ClassVersion("1.0.0"),
Description("File resource module manager class inheriting from OMI_ResourceModuleManager class") ]
class MSFT_FileResourceManager : OMI_ResourceModuleManager
{
[Description ("String UNC path of the File resource manager" ) , Key]
string SourcePath;
[EmbeddedInstance("MSFT_Credential"),
Description ("Default credential to access resources." ) ]
string Credential;
};
[Description(
"This represents a Partial Configuration class."),
ClassVersion("1.0.0")]
class MSFT_PartialConfiguration : OMI_MetaConfigurationResource
{
[Description ("Description of the partial configuration" ) , Write]
String Description ;
[Description ("Defines the resources that are exclusive to this particular partial configuration" ) , Write]
String ExclusiveResources[];
[Description ("The configuration repository source that this partial configuration will use" ) , Write]
String ConfigurationSource;
[Description ("A dependency variable indicating which partial configuration must be applied prior to this" ) , Write]
String DependsOn[];
};

View file

@ -0,0 +1,7 @@
#pragma namespace("\\\\.\\root\\microsoft\\windows\\DesiredstateConfiguration")
[ClassVersion("1.0.0"),FriendlyName("Log")]
class MSFT_LogResource : OMI_BaseResource
{
[required] string Message;
};

View file

@ -0,0 +1,10 @@
[ClassVersion("1.0.0"), FriendlyName("nxArchive")]
class MSFT_nxArchiveResource : OMI_BaseResource
{
[Key] string SourcePath;
[Key] string DestinationPath;
[write,ValueMap{"ctime", "mtime", "md5"},Values{"ctime", "mtime","md5"}] string Checksum;
[write] boolean Force;
[Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
};

View file

@ -0,0 +1,8 @@
[ClassVersion("1.0.0"), Description("The configuration provider for environment variable control."), FriendlyName("nxEnvironment")]
class MSFT_nxEnvironmentResource:OMI_BaseResource
{
[Key] string Name;
[write] string Value;
[Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[Write] boolean Path;
};

View file

@ -0,0 +1,8 @@
[ClassVersion("1.0.0"), FriendlyName("nxFileLine")]
class MSFT_nxFileLineResource : OMI_BaseResource
{
[key,required] string FilePath;
[write] string DoesNotContainPattern;
[key,write] string ContainsLine;
};

View file

@ -0,0 +1,17 @@
[ClassVersion("1.0.0"), Description("The configuration provider for files and directories."), FriendlyName("nxFile")]
class MSFT_nxFileResource:OMI_BaseResource
{
[Key] string DestinationPath;
[Write] string SourcePath;
[Write,ValueMap{"present", "absent"},Values{"present", "absent"}] string Ensure;
[Write,ValueMap{"file", "directory", "link"},Values{"file", "directory","link"}] string Type;
[Write] boolean Force;
[Write] string Contents;
[Write, ValueMap{"md5", "mtime", "ctime"}] string Checksum;
[Write] boolean Recurse;
[Write, ValueMap{"follow", "manage", "ignore" }] string Links;
[Write] string Group;
[Write] string Mode;
[Write] string Owner;
[Read] datetime ModifiedDate;
};

View file

@ -0,0 +1,12 @@
[ClassVersion("1.0.0"), FriendlyName("nxGroup")]
class MSFT_nxGroupResource:OMI_BaseResource
{
[Key] string GroupName;
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[write] string Members[];
[write] string MembersToInclude[];
[write] string MembersToExclude[];
[write] string PreferredGroupID;
[read] string GroupID;
};

View file

@ -0,0 +1,19 @@
[ClassVersion("1.0.0"), FriendlyName("nxPackage")]
class MSFT_nxPackageResource : OMI_BaseResource
{
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[write,ValueMap{"Yum", "Apt", "Zypper", "*"},Values{"Yum", "Apt", "Zypper", "*"}] string PackageManager;
[Key] string Name;
[write] string FilePath;
[write] Boolean PackageGroup;
[write] string Arguments;
[write] uint32 ReturnCode;
[read] string PackageDescription;
[read] string Publisher;
[read] string InstalledOn;
[read] uint32 Size;
[read] string Version;
[read] boolean Installed;
[read] string Architecture;
};

View file

@ -0,0 +1,10 @@
[ClassVersion("1.0.0"),FriendlyName("nxScript")]
class MSFT_nxScriptResource : OMI_BaseResource
{
[Key] string GetScript;
[Key] string SetScript;
[Key] string TestScript;
[write] string User;
[write] string Group;
[Read] string Result;
};

View file

@ -0,0 +1,12 @@
/* I am really new */
[ClassVersion("1.0.0"), FriendlyName("nxService")]
class MSFT_nxServiceResource : OMI_BaseResource
{
[key] string Name;
[write,required,ValueMap{"init", "upstart", "systemd", "*"},Values{"init","upstart","systemd", "*"}] string Controller;
[write] boolean Enabled;
[write,ValueMap{"Running", "Stopped"},Values{"Running", "Stopped"}] string State;
[read] string Path;
[read] string Description;
[read] string Runlevels;
};

View file

@ -0,0 +1,8 @@
[ClassVersion("1.0.0"), Description("The configuration provider for ssh authorized key control."), FriendlyName("nxSshAuthorizedKeys")]
class MSFT_nxSshAuthorizedKeysResource:OMI_BaseResource
{
[Key] string KeyComment;
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[write] string UserName;
[write] string Key;
};

View file

@ -0,0 +1,15 @@
[ClassVersion("1.0.0"), FriendlyName("nxUser")]
class MSFT_nxUserResource : OMI_BaseResource
{
[Key] string UserName;
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[write] string FullName;
[write] string Description;
[write] string Password;
[write] boolean Disabled;
[write] boolean PasswordChangeRequired;
[write] string HomeDirectory;
[write] string GroupID;
[read] string UserID;
};