Skip to content

Commit b8ccc7d

Browse files
authored
Merge pull request #1441 from SteveL-MSFT/exe-info
Fix executionInformation in config export result
2 parents bdef8b0 + fb15f2a commit b8ccc7d

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

adapters/powershell/Tests/powershellgroup.config.tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ Describe 'PowerShell adapter resource tests' {
126126
$res.resources[0].properties.result.count | Should -Be 1
127127
$res.resources[0].properties.result[0].Name | Should -Be "FilteredExport"
128128
$res.resources[0].properties.result[0].Prop1 | Should -Be "Filtered Property for FilteredExport"
129-
"$TestDrive/export_trace.txt" | Should -FileContentMatch "Properties provided for filtered export" -Because (Get-Content -Raw -Path $TestDrive/export_trace.txt)
129+
$traceLog = Get-Content -Raw -Path "$TestDrive/export_trace.txt"
130+
$traceLog | Should -BeLike "*Properties provided for filtered export*" -Because $traceLog
130131
}
131132

132133
It 'Export fails when filtered export is requested but not implemented' {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'config export tests' {
5+
It 'Execution information is included in config export results' {
6+
$config_yaml = @'
7+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
8+
resources:
9+
- name: os
10+
type: Microsoft/OSInfo
11+
'@
12+
13+
$out = dsc config export -i $config_yaml | ConvertFrom-Json
14+
$LASTEXITCODE | Should -Be 0
15+
$out.executionInformation | Should -Not -BeNullOrEmpty
16+
$out.executionInformation.startDatetime | Should -Not -BeNullOrEmpty
17+
$out.executionInformation.endDatetime | Should -Not -BeNullOrEmpty
18+
$out.executionInformation.duration | Should -Not -BeNullOrEmpty
19+
$out.executionInformation.operation | Should -BeExactly 'export'
20+
$out.executionInformation.executionType | Should -BeExactly 'actual'
21+
$out.executionInformation.securityContext | Should -Not -BeNullOrEmpty
22+
$out.executionInformation.version | Should -BeExactly (dsc --version).replace("dsc ", "")
23+
$out.resources | Should -Not -BeNullOrEmpty
24+
$out.resources.count | Should -Be 1
25+
$out.resources[0].Name | Should -Not -BeNullOrEmpty
26+
$out.resources[0].type | Should -BeExactly 'Microsoft/OSInfo'
27+
$out.resources[0].executionInformation | Should -Not -BeNullOrEmpty
28+
$out.resources[0].executionInformation.duration | Should -Not -BeNullOrEmpty
29+
$out.resources[0].properties.family | Should -BeIn @('Windows', 'Linux', 'macOS')
30+
$out.resources[0].properties.architecture | Should -BeIn @('x86_64', 'arm64')
31+
$out.resources[0].properties.version | Should -Not -BeNullOrEmpty
32+
$out.resources[0].properties.bitness | Should -BeIn @(32, 64)
33+
}
34+
}

lib/dsc-lib/src/configure/config_doc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub struct Output {
299299
}
300300

301301
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, DscRepoSchema)]
302-
#[serde(deny_unknown_fields)]
302+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
303303
#[dsc_repo_schema(
304304
base_name = "document",
305305
folder_path = "config",
@@ -314,7 +314,6 @@ pub struct Configuration {
314314
#[serde(rename = "$schema")]
315315
#[schemars(schema_with = "Configuration::recognized_schema_uris_subschema")]
316316
pub schema: String,
317-
#[serde(rename = "contentVersion")]
318317
pub content_version: Option<String>,
319318
#[serde(skip_serializing_if = "Option::is_none")]
320319
pub directives: Option<ConfigDirective>,
@@ -467,15 +466,15 @@ pub struct Sku {
467466
}
468467

469468
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, DscRepoSchema)]
470-
#[serde(deny_unknown_fields)]
469+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
471470
#[dsc_repo_schema(base_name = "document.resource", folder_path = "config")]
472471
pub struct Resource {
473472
#[serde(skip_serializing_if = "Option::is_none")]
474473
pub condition: Option<String>,
475474
/// The fully qualified name of the resource type
476475
#[serde(rename = "type")]
477476
pub resource_type: FullyQualifiedTypeName,
478-
#[serde(skip_serializing_if = "Option::is_none", rename = "requireVersion", alias = "apiVersion")]
477+
#[serde(skip_serializing_if = "Option::is_none", alias = "apiVersion")]
479478
pub require_version: Option<ResourceVersionReq>,
480479
/// A friendly name for the resource instance
481480
#[serde(default)]
@@ -488,7 +487,7 @@ pub struct Resource {
488487
pub execution_information: Option<ExecutionInformation>,
489488
#[serde(skip_serializing_if = "Option::is_none")]
490489
pub location: Option<String>,
491-
#[serde(rename = "dependsOn", skip_serializing_if = "Option::is_none")]
490+
#[serde(skip_serializing_if = "Option::is_none")]
492491
#[schemars(regex(pattern = r"^\[resourceId\(\s*'[a-zA-Z0-9\.]+/[a-zA-Z0-9]+'\s*,\s*'[a-zA-Z0-9 ]+'\s*\)]$"))]
493492
pub depends_on: Option<Vec<String>>,
494493
#[serde(skip_serializing_if = "Option::is_none")]

lib/dsc-lib/src/configure/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ macro_rules! find_resource_or_error {
102102
///
103103
/// * `resource` - The resource to export.
104104
/// * `conf` - The configuration to add the results to.
105+
/// * `input` - The input to the export operation.
105106
///
106107
/// # Panics
107108
///
@@ -112,11 +113,15 @@ macro_rules! find_resource_or_error {
112113
/// This function will return an error if the underlying resource fails.
113114
pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf: &mut Configuration, input: &str) -> Result<ExportResult, DscError> {
114115

116+
let start_datetime = chrono::Local::now();
115117
let export_result = resource.export(input)?;
118+
let end_datetime = chrono::Local::now();
116119

117120
if resource.kind == Kind::Exporter {
118121
for instance in &export_result.actual_state {
119-
let resource = serde_json::from_value::<Resource>(instance.clone())?;
122+
let mut resource = serde_json::from_value::<Resource>(instance.clone())?;
123+
let execution_information = ExecutionInformation::new_with_duration(&start_datetime, &end_datetime);
124+
resource.execution_information = Some(execution_information);
120125
conf.resources.push(resource);
121126
}
122127
} else {
@@ -157,7 +162,7 @@ pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf
157162
}
158163
r.properties = escape_property_values(&props)?;
159164
let mut properties = serde_json::to_value(&r.properties)?;
160-
let mut execution_information = ExecutionInformation::new();
165+
let mut execution_information = ExecutionInformation::new_with_duration(&start_datetime, &end_datetime);
161166
get_metadata_from_result(None, &mut properties, &mut metadata, &mut execution_information)?;
162167
r.properties = Some(properties.as_object().cloned().unwrap_or_default());
163168
r.metadata = if metadata.microsoft.is_some() || !metadata.other.is_empty() {
@@ -938,6 +943,9 @@ impl Configurator {
938943
},
939944
}
940945

946+
let mut execution_information = ExecutionInformation::new();
947+
self.get_execution_information(Operation::Export, &mut execution_information);
948+
conf.execution_information = Some(execution_information);
941949
result.result = Some(conf);
942950
self.process_output()?;
943951
if !self.context.outputs.is_empty() {

0 commit comments

Comments
 (0)