In the years since the dissolution of the USSR, Shostakovich's reputation in the West has fluctuated wildly: for quite a while, he was considered an intellectually slavish servant of Soviet ideology and the aesthetic of Socialist Realism. In 1979, four years after Shostakovich's death, an alleged disciple of his named Solomon Volkov published what were purported to be Shostakovich's memoirs, constructed from long conversations Volkov claimed the two of them had before his death.
The book, which portrayed Shostakovich as a composer inhibited forcibly by a Soviet regime he despised totally and with great vitriol, dramatically altered the West's perception of him. As the Cold War still divided the world, a book which claimed that the (unquestionably) great composer was actually an anti-communist and loathed the USSR was of course met with success and credulity.
As it happens, however, most scholars now agree that Volkov faked the work, and did not know Shostakovich very well at all. Among Volkov's foremost critics is Shostakovich's widow, who claims that her husband met with Volkov very briefly, and that her husband bore no resemblance to the picture painted by the memoirs.
What is most likely is also what is most intuitive: Shostakovich probably loved his country, feared his government, and cared little for politics, preferring instead his music.
Early in his career he was hailed as the greatest Soviet composer (Stravinsky having been born in the tsarist era and having left the country), and was a favorite of Stalin. Stalin was notoriously fickle, however, and walked out of a performance of Lady Macbeth of the Mtsensk District, an opera which had previously been quite successful.
To say the least, this devastated Shostakovich; he lost his position at the university, was roundly castigated by the music critics, and eventually had to apologize for his opera's alleged "petit-bourgeoisie" sympathies.
Stalin, however, resurrected him just as quickly after the Fifth Symphony, and Shostakovich's success continued for some time, although it is said that he kept a suitcase packed in case Stalin changed his mind.
In 1948, Andrei Zhdanov, the chief ideologue of the Soviet party and a close associate of Stalin, issued a decree on Russian music which forbade "formalism," an essentially meaningless term which could be applied to virtually any work. In this unfortunate instance, it was applied to Shostakovich, and once again he was humiliated and forced to repent, vowing to mend his ways. Again, however, he was soon enough returned to his original place at the pinnacle of the Soviet music hierarchy.
Despite the very severe difficulties that living in the Soviet Union caused him, he never defected, though he had numerous opportunities (including a trip to New York) and would have been fully supported by any Western nation.
As such, Shostakovich probably felt (as many people do) both affection and disdain for his country, and the end felt most strongly about his music (which, by the way, is wonderful, and I regret not discussing it instead).